一、sudo 简介
sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登录和管理时间,同样也提高了安全性。sudo不是对shell的一个代替,它是面向每个命令的。
sudo:暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码。不过有时间限制。
sudo -i:为了频繁的执行某些只有超级用户才能执行的权限,而不用每次输入密码,可以使用该命令。提示输入密码时该密码为当前账户的密码。没有时间限制。执行该命令后提示符变为 "#" 而不是 "$",想退回普通账户时可以执行 "exit" 或 "logout"。
二、sudo 配置文件
vim /etc/sudoers
# 在此处添加授权规则
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
# 格式
root # 指定用户
ALL=(ALL) #(ALL)括号内指定切换到哪个用户下执行命令,如为ALL,表示所有用户,如为空,是root用户
ALL # 表示可以执行所有命令
1、tomma 用户以root运行所有命令
## Allow root to run any commands anywhere
tomma ALL=(ALL) ALL
2、tomma 用户输入sudo免密码
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
tomma ALL=(ALL) NOPASSWD: ALL
3、配置 developer 用户组下所有成员运行指定命令
# 默认 wheel 组都有 sudo 权限
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
%developer ALL=(ALL) /usr/sbin/nginx,/usr/bin/kill