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?
Comments (most recent first)
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 ?
|
|
|
![]() |
|
| <Send This Link to a Friend> <Bookmark This Page> | ||