Linux Classes
Share This With a Friend  
LINUX CLASSES - LINUX COMMANDS

How Do I Switch Users Under Linux?

Even if you have no schizophrenic tendencies, sometimes you'll want to become someone else while using Linux. For example, if you're logged in as hermie and you need to do something quickly that requires superuser authority, just enter the command su - root

In response to the su (switch user) command, you'll be prompted for the root account password. If you enter the password correctly, your prompt will change from a dollar sign to a pound sign (to reflect your status as root), and you will assume the powers of the root user. Issue the command

exit

to return to your previous identity. You can also use su to become any user on the system, not just root. For example, to become sigmund, you would enter this command:

su - sigmund

Don't forget the minus sign when you use su to temporarily become another user. Without it, the login profilefor that user is not executed--so it's not really the same as logging in, because your environment variables, and aliaseswould not change.

This would be like starting DOS without running the autoexec.bat file--things wouldn't work the same, because your personal setup commands (PATH and so on) would not run.

But why would you want to use su when you can have multiple log-ins via virtual consoles (see "Living in a Shell")? Because it's sometimes quicker or more convenient to switch between users using su, and because you may have no virtual consoles available--you may be using all of them or, if you're logged in to the machine via a modem, virtual consoles may not be available to you.

Previous Lesson: Changing Your Password
Next Lesson: Who is Logged In?

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

sandeep dubey     (16 May 2012, 08:51)
Sir kaise pen drive ko format ko karte h cmd ke through plz batane ki kripa kare
raymond     (24 Mar 2012, 03:33)
can root group contain many users on linux ? would you tell me the information
RR21     (13 Mar 2012, 15:48)
Are there any instances where using the "su" command without the "-" is practical?
Anonymous     (03 Mar 2012, 14:13)
I type su and when it asks for my pass i can't type it .Canyou help me
Pritha     (25 Feb 2012, 10:58)
sir,can you please tell me what is the difference between the su and sudo commands.
Neel     (17 Feb 2012, 04:43)
thanks
jude     (07 Jan 2012, 02:33)
hi sir,
i had mounted some files from server to client in linux...but i cant able to use that files in the client on user...pls tell the command to share root with user..
AVINASH     (26 Nov 2011, 13:21)
sir
i want to make a script program which can enter as a oracle with password
after then it will enter in sql dthrough the sqlplus command and it will able to exec query .
can it possible? if yes please give me the way.
Pranava     (09 Oct 2011, 16:49)
I cant access the root directory even after entering the password for my laptop. Is the password for the root directory different from the one for my laptop?
B     (21 Sep 2011, 09:58)
A more common reason is that a user admin has blocked ssh/rlogin as a root account. For root access, one must access at a lower permission level, and then elevate permissions as needed using su. This reduces an attackers ability to gain access to the root account, and helps prevent mindless root access.
Madhu     (16 Jun 2011, 09:11)
hi
how copy the entair directory from root user to switch user using linux command
if u konw send me ASAP.............
thanku........
sander     (12 Mar 2011, 10:13)
@ken

try to find grub ;) you can find grub in ubuntu under preferences
Ken Palmer Sr     (19 Feb 2011, 08:50)
Ken
I installed linux on a partition on my hard drive so I thought and I was going to use windows and linux and now I cannot get the windows system to come back up when I reboot it do not give me the option to boot from either drive that I may want, have I lost the windows os or can I recover it ?
Bob Rankin     (16 Dec 2010, 09:18)
@vishal - the su command is just "switch user". The sudo command means "execute a command as that user".
vishal     (14 Dec 2010, 10:36)
difference between 'su' and 'sudo' command in ?

sometimes we will use 'sudo su' together...?
Bob Rankin     (02 Aug 2010, 11:12)
CentOS is a free clone of RedHat Enterprise Linux.
jitendra kumar     (31 Jul 2010, 06:44)
what is centos
PC     (02 Jul 2010, 17:36)
Hey Kelvin use sudo -i
surya     (29 Jun 2010, 04:07)
REAlly good and usefull
syl grove     (25 Jun 2010, 22:10)
good job bob
viji     (03 Jun 2010, 08:37)
Great teaching sir thankyou
I added a user from root but when I try to see the list of users it does not show me the new user. It shows both the users as root and the number as 2
pl explain. (I was trying to su without -, i used su user and later typed su - user which prompted for p/w)
regards
anand     (22 May 2010, 04:38)
i want change the current user is root to admin and the group root to owner.In system what command i should use???
Bob Rankin     (30 Apr 2010, 05:25)
The difference is explained above.
vishalb     (29 Apr 2010, 15:30)
In switch user; we will type the command su - root
su root what are the diffrences onthis.

we will swith in to root user only right.
jokish     (12 Apr 2010, 09:06)
how to breakubuntu's root password?
Nolan     (06 Apr 2010, 01:01)
kevin...
code: "su - root"
-->press "Enter"
It will ask for the password for root.
code: "xxxxxxxxxx" <--use your root password.
-->press "Enter"
If the password was correct..the prompt will change from a "$" to a "#".
You now have the power to destroy your system. :)
NOTE: All enteres are without the quotes. '"'
kelvin benson     (03 Apr 2010, 02:45)
i am trying out an installation manaually and i supposed to switch to root like this: [nubuntu@nubuntu] su - passwd:[leave blank] then it will change to [root@nubuntu] i have tried it and i am not getting to root. can anyone help me?
Bob Rankin     (02 Mar 2010, 05:14)
Yes, it's the same idea.
Dennis     (02 Mar 2010, 00:21)
is autoexec.bat in DOS quite the same as .profile in bash ?

I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.