[oldboy@oldboyedu ~]$ ls /root
ls: cannot open directory /root: Permission denied
完成上面的动作。
给oldboy用户,针对ls设置权限。
visudo进入编辑状态,100G
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
oldboy ALL=(ALL) /usr/bin/ls,/bin/cp #<===增加一行
用户 主机=(角色) 命令
注意:
1、路径要全路径:
which cp查
2、不要vim /etc/sudoers编辑,如果非要用编辑完visudo -c检查语法
oldboy是管理员,并且不要密码:
oldboy ALL=(ALL) NOPASSWD: ALL
登录后切到root运行。
[oldboy@oldboyedu ~]$ sudo su - root
Last login: Tue Mar 26 10:32:57 CST 2019 on pts/3
[root@oldboyedu ~]#
为了安全禁止root远程连接linux。
工作中如何登录?使用普通用户登录然后利用sudo提权到root。
Wecomle to oldboy training 58期。
[oldboy@oldboyedu ~]$ whoami
oldboy
[oldboy@oldboyedu ~]$ sudo ls /root
a.txt c.txt data1 etc oldboy oldboy_b oldboy_soft_link pass test.txt user.log
b.txt d d.txt grep.txt oldboy_1.txt oldboyedu.txt oldboy.txt test test.txt.ori
[oldboy@oldboyedu ~]$
[oldboy@oldboyedu ~]$ sudo su -
Last login: Tue Mar 26 11:42:09 CST 2019 on pts/0
[root@oldboyedu ~]#
[root@oldboyedu ~]# su - oldboy
Last login: Tue Mar 26 10:44:08 CST 2019 on pts/3
[oldboy@oldboyedu ~]$ ls /root
ls: cannot open directory /root: Permission denied
[oldboy@oldboyedu ~]$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for oldboy:
Matching Defaults entries for oldboy on oldboyedu:
User oldboy may run the following commands on oldboyedu:
(ALL) /bin/ls
[oldboy@oldboyedu ~]$ sudo ls /root
a.txt c.txt data1 etc oldboy oldboy_b oldboy_soft_link pass test.txt user.log
b.txt d d.txt grep.txt oldboy_1.txt oldboyedu.txt oldboy.txt test test.txt.ori
[oldboy@oldboyedu ~]$ ls /root
ls: cannot open directory /root: Permission denied
[oldboy@oldboyedu ~]$
3 - 26 命令笔记
groupadd 添加用户组
-g 指定组ID
chage 改变用户密码属性
-l 显示用户的密码信息
- E 修改账户过期时间
id 查看用户身份
whoami 查看当前登录用户
w 查看所有用户
last 显示登录过的用户信息
lastlog 查看最近登录过的报告
su 用户身份切换
- 携带环境变量登录
sudo 允许指定用户执行某命令期间拥有root角色权限
-l 查看获得的权限
visudo 编辑sudo配置文件文件命令
-l 检查配置文件语法