su、sudo、限制root远程登录

su命令

su:切换用户

1、root用户切换test用户不需要密码

[root@test ~]# su - test

[test@test ~]$


2、普通用户切换为root用户就需要密码

[test@test ~]$ su -

Password: #root密码

[root@test ~]# 

3、需要加上-,这个表示真正切换了用户


sudo命令

1、是限制版的su命令。

su命令缺点:当十个用户切换到root用户来执行命令时,10个人就需要指定root账号的密码,很不安全。

sudo:可以使用root身份才执行命令,可以分配权限给用户

[root@test ~]# visudo 

#新增用户别名

User_Alias ADMINS = test,gztest

#新增命令别名

## ls

Cmnd_Alias LS=/bin/ls,/bin/rm

#针对op组做权限设置

%op     ALL=(root)        LS


[root@test ~]# su - test

[test@test ~]$ ls /root/  #没权限

ls: cannot open directory /root/: Permission denied

[test@test ~]$ sudo ls /root/  #加上sudo 就有权限了

[sudo] password for test: #输入test用户密码

123.txt  2.txt2.txt.bak  anaconda-ks.cfg  get-pip.pyindex.php  test

[test@test ~]$ sudo rm -f /root/123.txt

[test@test ~]$ ls /root/

ls: cannot open directory /root/: Permission denied

[test@test ~]$ sudo ls /root/

2.txt  2.txt.bak  anaconda-ks.cfg  get-pip.py  index.php  test


限制root远程登录

设置test用户无密码访问root

[root@test-7 ~]# visudo 

## Allow root to run any commands anywhere

root    ALL=(ALL)       ALL

test    ALL=(ALL)       NOPASSWD: ALL



1、[root@test-7 ~]# vi /etc/ssh/sshd_config

PermitRootLogin no


2、用test用户登录

[test@test-7 ~]$ whoami

test

 

[test@test-7 ~]$ sudo su -


[root@test-7 ~]# whoami

root

'













本文转自方向对了,就不怕路远了!51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1978178 ,如需转载请自行联系原作者



上一篇:用nifi把hdfs数据导到hive


下一篇:linux防火墙iptables配置规则分享