1新建一个新用户tommy
[root@xie-test~]#Useradd tommy
[root@xie-test~]#Passwd tommy
输入密码:
确认密码
2修改sudoers配置文件
[root@xie-test~]#vi /etc/sudoers
找到下面这一行,添加tommy用户让其拥有root用户sudo权限
## Allow root torun any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL
为了方便测试,我们现在/root目录下新建一个test.txt文件
[root@xie-test~]#vi /root/test.txt
[root@xie-test~]#ls –l /root/test.txt
-rw-r--r-- 1root root 191 8月 28 17:40 /root/test.txt
可以看到这个文件只有root用户拥有读写功能
3修改sshd_Config文件
[root@xie-test~]# vi /etc/ssh/sshd_config
找到PermitRootLogin这里,删除前面的#号并且修改为no
#LoginGraceTime2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
重启sshd服务
[root@xie-test~]# service sshd restart
4测试用putty或者securecrt以root身份远程登录,发觉无论怎么输入密码都无法登录,然后我们用tommy用户登录显示
[tommy@xie-test~]$
这里还只是tommy用户权限,那么我们就可以使用sudo命令来编辑root权限的文件sudo vi /root/test.txt
然后我们可以编辑这个文件并且保存,证明可以使用root用户权限了
另外,其实在网上可以搜到另外一种办法就是使用usermod将新建的用户添加至root分组,这样会出现一个问题,只有当root分组拥有和root用户同等权限的时候,这个用户才有root用户的权限,例如root组有读和写权限,那么这个新建的用户就有读和写的权限,但是如果root组只有读权限,那么这个新建的用户也就只有读权限,所以在这里不建议使用这种办法