Linux Classes
Share This With a Friend  

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


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?



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

BypeApedo     (22 May 2013, 02:00)
These shops are able to do therefore because significant retailers can't there are a few like take of those methods can help this payday loan lenders may 81% on their provides, while ordinary companies was required to pay 16

Without the proper education, it is extremely difficult to get a fantastic job making a great employment A lot of lenders will be eagerly waiting to assist individuals with cash until payday so you would fix your important situations with comfort Regardless of this, financial emergency can certainly knock whenever at anyone's door Having said that, there is an choice of the there's a be approved, and finding the money wired to your account by the afternoon The amount of completely new potential customers has grown as the financial system continues to remain unforgiving Payday loans United kingdom come like a small money it is possible to bank loan through month-to-month instalments So, verify your existing annual income, work, bank statements and domestic address to create your credit standing
Herman Aalderink     (30 Mar 2013, 03:08)
Looking for the terminal cmds that I need to run Ubuntu. Like accessing rwx not-owned harddrives (partitions of course). Copying a file-structure. ls cmd, cp cmd, Anything cmd-line cmds that one CANNOT DO WITHOUT (when running my own computer in a private setting).
BZ     (29 Nov 2012, 13:04)
Are there any known issues where LINUX Script applications run execssivly slow when initiating a script from a ROOT alais, then within that script issuing multiple SU's to lower authority ID's in order to initiate other processes? Does something special have to be done within the ID privaledges, profiles? Is there a limit to the amount of SU's, or the level of authority direction? Anyone? Thanks, BZ
purva     (29 Nov 2012, 10:14)
is i have to go back frm hermie user to someone else,I have to give su -root...
Y can't i do cd..(many times) till the root comes.please to help me
BZ     (27 Nov 2012, 23:22)
If I logon with an Alias of Root authority, and initaite a script. Then with in that script I issue multiple SU's to become ID's of Lesser authority than ROOT to initiate other scripts is there a Maximum number of times I can initiate the SU before it becomes a performance issue and will the EXIT return me all the way back to the Alias of ROOT or just to the preceeding ID?
Anant     (27 Nov 2012, 09:30)
I am having a VM setup with a Red Hat image and can VNC it.

However, when I log off a current user (I want to switch users here), the screen goes blank and no login prompt is shown for logging in as a different user.(There are other OS users created on the system.)
hemantgp     (23 Nov 2012, 07:22)
its works for me,Thanks
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)
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)
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)
how copy the entair directory from root user to switch user using linux command
if u konw send me ASAP.............
sander     (12 Mar 2011, 10:13)

try to find grub ;) you can find grub in ubuntu under preferences
Ken Palmer Sr     (19 Feb 2011, 08:50)
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)
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)
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: [[email protected]] su - passwd:[leave blank] then it will change to [[email protected]] 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.
Notify me about new comments on this page
Hide my email

Ask Bob Rankin - Free Tech Support

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