LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   logging into the root in terminal (https://www.linuxquestions.org/questions/linux-newbie-8/logging-into-the-root-in-terminal-457143/)

MrSako 06-22-2006 12:57 AM

logging into the root in terminal
 
i have centos 4.3 with gnome graphical desktop. i have a root login and a user login. id normally work as a user and use root to do things like install applications. the thing is i cant just keep logging out and into root to install something with yum or something and then go back.

what i would like ot do is be able to log into root in the terminal and have root privledges until i logout of root in the terminal. or something very much like this.

pljvaldez 06-22-2006 01:05 AM

This is what the su command or sudo command is for. man su or man sudo. su lets you become root (you should use gksu to run gui apps as root) and sudo lets you do things as a user with root priveledges.

timmeke 06-22-2006 02:57 AM

As pljvaldez suggests, su and sudo are your friends.

su or "switch user" let's you use another user's account without having to logout/login.
Type "exit" to go back to your original (login) user.
Examples:
Code:

su  #switches to root user (providing you have password)
su - #also switches to root user, but also loads root's environment settings (like $PATH)
su some_user #switches to user "some_user" (again, you'll need that user's password)

sudo needs to be configured by root and allows certain users, to execute certain commands as if they were root.
They won't need root's password for this. root should set up the /etc/sudoers file. Needless to say, making normal users run programs as root, can create security hazards. So use it with care.
You won't need to "exit" after sudo'ing, because sudo only let's you execute just one command.
Example:
Code:

sudo some_command #will execute "some_command" as root, if /etc/sudoers file allows it

Tinkster 06-22-2006 03:14 AM

Quote:

Originally Posted by timmeke
As pljvaldez suggests, su and sudo are your friends.

su or "switch user" let's you use another user's account without having to logout/login.
Type "exit" to go back to your original (login) user.
Examples:
Code:

su  #switches to root user (providing you have password)
su - #also switches to root user, but also loads root's environment settings (like $PATH)
su some_user #switches to user "some_user" (again, you'll need that user's password)


And
Code:

su [-] <user> -c "command1; command2; command3; .... "
(The syntax depends on your version of su, it may vary, check the man-page)

lets you execute commands as the other user without requiring a shell.
That way you can't forget to type exit ;}


Cheers,
Tink


All times are GMT -5. The time now is 10:57 PM.