在Ubuntu 中如何配置运行用户sudo 权限
场景:
(base) root@gpu-63:/data1/public_user01# sudo su - ycx
ycx@gpu-63:~$ ls
public_user00
ycx@gpu-63:~$ pwd
/home/ycx
ycx@gpu-63:~$ ls
public_user00
ycx@gpu-63:~$ sudo /bin/ls
[sudo] password for ycx:
ycx is not in the sudoers file. This incident will be reported.
ycx@gpu-63:~$ exit
logout
步骤:
1)打开sudoers 包含文件
#includedir /etc/sudoers.d
(base) root@gpu-63:/data1/public_user01# more /etc/sudoers
(base) root@gpu-63:/data1/public_user01# chmod u+w /etc/sudoers
(base) root@gpu-63:/data1/public_user01# vi /etc/sudoers
(base) root@gpu-63:/data1/public_user01# chmod u-w /etc/sudoers
(base) root@gpu-63:/data1/public_user01# more /etc/sudoers
2)编辑ycx独立文件
(base) root@gpu-63:/data1/public_user01# chmod u+w /etc/sudoers
(base) root@gpu-63:/data1/public_user01# vi /etc/sudoers
(base) root@gpu-63:/data1/public_user01# tail /etc/sudoers
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
(base) root@gpu-63:/data1/public_user01# echo "ycx ALL=(ALL) ALL" | sudo tee /etc/sudoers.d/ycx
ycx ALL=(ALL) ALL
(base) root@gpu-63:/data1/public_user01# ls /etc/sudoers.d/
README ycx
(base) root@gpu-63:/data1/public_user01# cat /etc/sudoers.d/ycx
ycx ALL=(ALL) ALL
(base) root@gpu-63:/data1/public_user01# chmod u-w /etc/sudoers
(base) root@gpu-63:/data1/public_user01#