Jephe Wu - http://linuxtechres.blogspot.com
Envirnment: CentOS 6.4 64bit
Objective: understanding sudo command and common usages.
<username1> <ALL hosts>=(username2) [NOPASSWD:] commands
Above syntax will grant username1 to run commands as username2 on all hosts
1. sudo -l after you ssh into server
sudo -l will list the possible commands you could run
2. sudo -i to become root ( similiar to su - , using root user environment configuration including $HOME and $PATH)
Other similiar command such as sudo -s, sudo su and sudo bash.
3. sudo -k to clear password cache
You can also configure password cache time (minutes) in /etc/sudoers, by default, it's cached for 5 minutes, change to 0 will always ask for
password.
[root@server1 ~]# grep -i timestamp_timeout /etc/sudoers
Defaults timestamp_timeout=1
To totally disable password prompt, use NOPASSWD: between (ALL) and right-most ALL
<username> ALL=(ALL) NOPASSWD: ALL
4. always use visudo to edit /etc/sudoers instead of vi /etc/sudoers
visudo check syntax error
Note:
So you can remember above sudo command parameters by LIK(e), e for edit which uses visudo.
Refer to https://help.ubuntu.com/community/RootSudo