Learning is inevitable right, on that note I'm starting the Linux file system after
An Introduction to Linux and Terminal Basics , moving on to the next one.
cd / - switch to root directory
ls /home/ - listing the files in the home directory
here in this case listing users.
Now every process or command I run, it'll always run as me being the owner of that process. It does not require any permission for accessing the directories which reside in the user directory /home/USERNAME
but what if I need to run a command which accesses packages from / - root directory
or install new packages?
These tasks seem out of hand for USER
working with limited directories and permission.
Let's see if that's true:
The root user also known as a superuser or The Administrator is the most powerful user of all the users in the system. Even if there's only one human user in the system there are more users in the system itself like system daemons and more, you can know more about it using the command sudo cat /etc/passwd
/etc/passwd
is the file that contains data about all the users in the system.
The whole system files, packages, and applications come under the root, having root privileges means that one has complete control over the system, every Linux system has its own root user and there's only one.
As it is said Linux system is nothing but a group of files it is decided when the root permissions are needed and when not.
To view the permissions to a file or directories you can use the ll
command which stands for long list
cd
- for the user's home directory.cd ..
- for the previous directory from the present directorycd -
for the previous working directorycd ../..
command from the user's home directory and see where it leads to.
To get permission to perform the tasks of an administrator as a user we need to use the keyword sudo
as a prefix before the command, it stands for superuser do which again says that doing tasks as a root user.
While you're working on a project or setting up a new environment for an application or trying a new tool, sudo
prefix is necessary to install new software, application, or tools, you may have to use it multiple times over a period of time so it's better to switch to a temporary root session using the command sudo su
which stands for superuser do switch user
The terminal switches to a new shell session to run commands as the root user therefore we don't have to use sudo
multiple times
sudo su -
is the command to start a new shell for a temporary root session where the environment and path variables will the set to the root directory as if the root user has logged into the terminal.
exit or ctrl + d - To exit the shell
sudo
and su
are two different command operations, I can run the su
command without the sudo
prefix but it still asks for a password which is the root password and each time I run the su
command it asks for a password whereas the sudo
has a time limit of 15 minutes(it can be increased but not recommended) each time I run it, It doesn't ask for a password when sudo
is used in that time frame.
I can also extend the time limit by using the command sudo -v
for that particular session and sudo -k
to reset the time stamp.
I can always know more about the flags and the commands by using man command_name
sudo -s
, sudo -i
are the commands(recommended) that work the same as the sudo su
and sudo su -
command
su
command asks for the root password and it's disabled by default when I installed Ubuntu and started using it, I had to set the password for the root but what if I run the su
command before, then I cannot run it I need to set the password.sudo
prefix to log into the root shell, and we can permit who can use it while working in groups the admin can control that task so that the system administrator doesn't have to share the root passwordsudo
prefix to members of the group on who can use it and who cannot.
To change the password of the user or even the root user the command is sudo passwd USERNAME
, sudo
prefix not needed if you logged in as a root user
Running the command with no arguments provided changes the password of the root
Here are handy keyboard shortcuts for Ubuntu Desktop:
https://twitter.com/jksrtwt/status/1551131265918574593
Hope you got a good idea about sudo and root access. Happy learning buddy.