When to work as root & When to Work as a System User

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,249
Reaction score
2,391
Credits
3,828
When you should work as root

You have now installed Linux and the first thing you did was login as 'root'. Then you provided a password so that you and ONLY you could login to the system as 'root'. When you decide to work as root, you had better go into a phone booth first and change into a blue suit with a big 'S' on the front because 'root' is known as the 'superuser' (you can skip the red tights if you want).

That's really not meant to be just a witty reference to the Man of Steel. Actually, it is much more glamorous to be 'Superman' but root is actually more like the 'janitor' of the Linux system. Root has the keys to everything. He can shut off the lights, shut off the heat, lock you out of the building; he has to clean up the system and in the end make sure everything runs. And the most important thing about being a janitor - he sees everything.

'root' is not for routine work

As I mentioned, Linux makes your computer a true multi-user system, which means that besides root, you can and should work as another person. I say 'should' because doing routine work as 'root' could be hazardous to your health. When I first started using Linux myself, information was not all that readily available and I still had that 'one computer- one user' concept in my brain. It was after I had trashed all of the files and programs that make Linux run that I realized that working regularly as root wasn't a good idea.

Working as another user

Well, then how do you do your day to day work with Linux? That's easy. You do it by working as a user other than root. You may pick the name you like. Try your name. If your name is "Bob" then you could create a user account for 'bob'. By the way, if Prince Charles is reading this, Charles Philip Arthur George is a bit too long and has spaces, which Linux doesn't like - he should try 'charlie'. One thing I find EXTREMELY helpful is that with Linux, I can work as different people. It should not be inferred here that I have split-personality disorder. I am just a guy with a couple of different jobs. This way I can organize my work a lot better and backups are easier this way too.

Adding a new user

Well, Bob, now it's time to create your account. If your name is Hrothgar, use 'Hrothgar' or 'Hrothie' instead of 'bob' for the remainder of the lesson.

Now 'root' has to do this stuff. Yes, I know I just warned you about working as root, but this is where you have to exert your authority. Most major distributions have tools to do this. SuSE, for example, has a nice tool called YAST which lets you add users painlessly. You just fill in the correct information. Consult your Linux version for information on their tools. There is also the get-your-hands-dirty way of doing this. Actually you won't get your hands dirty unless you're eating barbecued ribs at the same time.

Using 'useradd' and 'passwd'

To add a new user, you can also use the command 'useradd'. Kind of a logical name, isn't it?

Try this:
Code:
useradd bob
You probably won't see any fireworks go off. You might not see anything. That doesn't matter. Linux has been told that there's a new user and his name's 'bob'.

Now you should give yourself a password.

Do this:
Code:
passwd bob

Linux will ask you for your password. Follow the same advice I gave previously about passwords. Also, don't use your 'root' password. Like 'one man, one vote' it's 'one user - one password'. You will be asked to repeat it.

What's in your user directory

When you create a new user, there is a directory created for that user in /home. To see what's in this new directory, you have to do the following.

Go to the /home directory. - typing:
Code:
cd /home

you can make sure you're in the /home directory by typing:
pwd
You'll see this: /home.

Now you need to type:
Code:
cd bob

You can type:
Code:
ls -a
to see what's in the directory. We'll go into more detail with the ls command later. With the -a option, you'll see some files that begin with a '.' (period/dot). Those would normally be hidden from you if you didn't use the -a.

Now you can go to work as 'bob', 'pcharles' or whoever you happen to be.
 


Is Android OS designed with Linux in mind?
What do you mean? Can you clarify your question?

Android IS a Linux-based operating system. It uses a modified Linux kernel at its heart.
 
What do you mean? Can you clarify your question?

Android IS a Linux-based operating system. It uses a modified Linux kernel at its heart.
It was kind of a joke. I reconized some of the elements from my phone.
 
When you should work as root

You have now installed Linux and the first thing you did was login as 'root'. Then you provided a password so that you and ONLY you could login to the system as 'root'. When you decide to work as root, you had better go into a phone booth first and change into a blue suit with a big 'S' on the front because 'root' is known as the 'superuser' (you can skip the red tights if you want).

That's really not meant to be just a witty reference to the Man of Steel. Actually, it is much more glamorous to be 'Superman' but root is actually more like the 'janitor' of the Linux system. Root has the keys to everything. He can shut off the lights, shut off the heat, lock you out of the building; he has to clean up the system and in the end make sure everything runs. And the most important thing about being a janitor - he sees everything.

'root' is not for routine work

As I mentioned, Linux makes your computer a true multi-user system, which means that besides root, you can and should work as another person. I say 'should' because doing routine work as 'root' could be hazardous to your health. When I first started using Linux myself, information was not all that readily available and I still had that 'one computer- one user' concept in my brain. It was after I had trashed all of the files and programs that make Linux run that I realized that working regularly as root wasn't a good idea.

Working as another user

Well, then how do you do your day to day work with Linux? That's easy. You do it by working as a user other than root. You may pick the name you like. Try your name. If your name is "Bob" then you could create a user account for 'bob'. By the way, if Prince Charles is reading this, Charles Philip Arthur George is a bit too long and has spaces, which Linux doesn't like - he should try 'charlie'. One thing I find EXTREMELY helpful is that with Linux, I can work as different people. It should not be inferred here that I have split-personality disorder. I am just a guy with a couple of different jobs. This way I can organize my work a lot better and backups are easier this way too.

Adding a new user

Well, Bob, now it's time to create your account. If your name is Hrothgar, use 'Hrothgar' or 'Hrothie' instead of 'bob' for the remainder of the lesson.

Now 'root' has to do this stuff. Yes, I know I just warned you about working as root, but this is where you have to exert your authority. Most major distributions have tools to do this. SuSE, for example, has a nice tool called YAST which lets you add users painlessly. You just fill in the correct information. Consult your Linux version for information on their tools. There is also the get-your-hands-dirty way of doing this. Actually you won't get your hands dirty unless you're eating barbecued ribs at the same time.

Using 'useradd' and 'passwd'

To add a new user, you can also use the command 'useradd'. Kind of a logical name, isn't it?

Try this:
Code:
useradd bob
You probably won't see any fireworks go off. You might not see anything. That doesn't matter. Linux has been told that there's a new user and his name's 'bob'.

Now you should give yourself a password.

Do this:
Code:
passwd bob

Linux will ask you for your password. Follow the same advice I gave previously about passwords. Also, don't use your 'root' password. Like 'one man, one vote' it's 'one user - one password'. You will be asked to repeat it.

What's in your user directory

When you create a new user, there is a directory created for that user in /home. To see what's in this new directory, you have to do the following.

Go to the /home directory. - typing:
Code:
cd /home

you can make sure you're in the /home directory by typing:
pwd
You'll see this: /home.

Now you need to type:
Code:
cd bob

You can type:
Code:
ls -a
to see what's in the directory. We'll go into more detail with the ls command later. With the -a option, you'll see some files that begin with a '.' (period/dot). Those would normally be hidden from you if you didn't use the -a.

Now you can go to work as 'bob', 'pcharles' or whoever you happen to be.

Thank you for sharing this information. Helpful and your choice of word is very simple. I 100% understand this explanation. :D:D:D
 
Depends if your name is Grendel. Our Rob has a sense of humour that works in mysterious ways, and the article was written 6 years ago. But let's not derail it :)

... and welcome, Daniel and others, to linux.org :D

Wizard
 
i've just realize that post is 6 years ago, but it still good for today.
i'm new in here
please be nice to me :)
 
Good tutorial. Explained neatly.
I believe people working on Linux for the first time i.e Linux beginners have this in mind - Let's not hassle, let's use root. Wish to work command on first time (if its correct not stuck on a Genie saying ' you don't have any wishes left'). :p Probably they know they will blunder their linux system in first try and will install fresh when they have proper knowledge. --Might be Isolated case of me--
One thing struck me again - what is wrong with naming in ling PWD for printing current working directory, lot more easier if one has to change password using it. :rolleyes:
 
Last edited:
So when I am on the terminal
It comes up with Mullity@Goldie ~
Does that mean that I am working at the Root/super user level?
Should that be the case then why are there times that I have to use sudo at the beginning of a command line. E.G sudo apt install.
I got the impression from other sources that sudo was used to turn you into the root user.
Just smoothing out and clarify info as I am slightly baffled and confused.
 
So when I am on the terminal
It comes up with Mullity@Goldie ~
Does that mean that I am working at the Root/super user level?
No, the tilde character ~ shows that you are a regular user. When you use sudo to execute a command, you are temporarily given root authority (after you give a password). If you close your terminal and re-open it, you will have lost the root authority and will have to enter the password again to use sudo on a command. If you leave your teminal open, your root authority may also time out if unused.

If you actually become root, the ~ character will change to a # character, and you no longer need to type sudo with your commands. As you surf the web and see people giving Linux command instructions, if you see the # at the beginning, they are telling you that you must be root, or use sudo, to execute the commands they are providing.

Things have changed over the years, and distros vary a bit on how to become root. Many (maybe most) will not let you log into your own system as root anymore. But if you have a lot of work to do that needs you to be root, you can become root so you do not constantly have to keep typing sudo. In some distros, just give the command su and provide the password. If that doesn't work, then try sudo su and give the password. The # character should appear to let you know that you were successful. When you finish your work, you should type exit twice... first to be sure that your root access is terminated, and the second one will close the terminal.

Cheers
 
When to work as root and when as rob?
I would work as a rob all year and as a root on my birthday. ;)
 
@atanere Thanks for clearing that little bit of confusion in my mind up.
I don't think that I will have the need to work as root that often so using sudo will be enough for my needs to keep it well maintained.
 

Staff online

Members online


Top