前言:
由于公司用户主机要收回root权限,很多用户连最基础的apt-get这些命令权限都没有,所以我只是想记录一下自己的笔记仅此而已。
环境:
linux系统
[root@localhost ~]# which 命令 #查找命令绝对路径
[root@localhost ~]# which apt-get
/usr/bin/apt-get
以下只是我想要用到的命令的绝对路径,自己需要什么命令,可以查
/automount/tools/adb,/automount/tools/fastboot,/usr/sbin/update-java-alternatives,/sbin/shutdown,/sbin/reboot,/usr/bin/apt-get,/usr/bin/dpkg,/bin/cp,/usr/sbin/service,/usr/bin/sshfs**
由于要给用户基础命令的权限,所以我只给了这些最基础的,上面涉及了adb,fastboot,update-java-alternatives,shutdown,reboot,apt-get,dpkg,cp,service,sshfs这些命令
vi /etc/sudoers
给普通用户添加仅对命令有sudo权限操作
root ALL=(ALL:ALL)
user ALL=(ALL)NOPASSWD:/automount/tools/adb,/automount/tools/fastboot,/usr/sbin/update-java-alternatives,/sbin/shutdown,/sbin/reboot,/usr/bin/apt-get,/usr/bin/dpkg,/bin/cp,/usr/sbin/service,/usr/bin/sshfs
解释:
user为用户
ALL为所有主机名
(ALL)指该普通用户可以以所有用户的权限来执行命令,可以填其他用户
NOPASSWD: 使用sudo执行命令时不再需要密码
/usr/sbin/service: 授权命令的绝对路径;(您想使用什么命令就可以which查绝对路径添加到对应的用户后边就行)