#2
不懂才问2019-03-05 00:20
|
login as: studypy
studypy@192.168.253.21's password:
Last login: Mon Mar 4 03:30:32 2019 from 192.168.253.249
[studypy@demoServer ~]$ su
Password:
[root@demoServer studypy]#
studypy是安全过程中,设置的本地账号,无sudo权限。
[sudo] password for studypy:
studypy is not in the sudoers file. This incident will be reported.
第二步,添加一个复杂用户名和密码的用户,加入sudo:
[studypy@demoServer ~]$ su
Password:
[root@demoServer studypy]# adduser Asdf_Qwer-314159265358979
[root@demoServer studypy]# passwd Asdf_Qwer-314159265358979
Changing password for user Asdf_Qwer-314159265358979.
New password: #假设的密码是AsdfQwer@345,当然还可以用随机生成工具,生成更难记的,位数更长的。
Retype new password:
passwd: all authentication tokens updated successfully.
[root@demoServer studypy]# vim /etc/sudoers
在“root ALL=(ALL) ALL”一行的后面加入“Asdf_Qwer-314159265358979 ALL=(ALL) ALL”,:wq!退出。
第三步,屏蔽root(我想过改名,但不太懂会造成什么其他影响,还是像ubuntu那样屏蔽吧,等进一步了解再做定论):
[Asdf_Qwer-314159265358979@demoServer studypy]$ sudo passwd -l root
[sudo] password for Asdf_Qwer-314159265358979:
Locking password for user root.
passwd: Success
[Asdf_Qwer-314159265358979@demoServer studypy]$ su root
Password:
su: Authentication failure
这回,关机都得sudo了
[Asdf_Qwer-314159265358979@demoServer ~]$ shutdown -h now
==== AUTHENTICATING FOR org.freedesktop.login1.power-off ===
Authentication is required for powering off the system.
Authenticating as: root
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to execute operation: Access denied
Must be root.
[Asdf_Qwer-314159265358979@demoServer ~]$ sudo shutdown -h now
[sudo] password for Asdf_Qwer-314159265358979:
第四步,将studypy的用户名和密码也改的非常复杂:
sudo usermod -l ZxcvAsdfQwer_123654 -d /home/ZxcvAsdfQwer_123654 -m studypy
sudo passwd ZxcvAsdfQwer_123654
最后一步,设置新sudo权限用户不能直接远程登录,需要普通用户登录后,su过去:
[Asdf_Qwer-314159265358979@demoServer ~]$ sudo vim /etc/ssh/sshd_config
#PermitRootLogin 去掉前面的#,后面的yes改为no
最后一行加上:DenyUsers Asdf_Qwer-314159265358979
sudo service sshd restart
这样,现在只有ZxcvAsdfQwer_123654可以通过ssh登录,而Asdf_Qwer-314159265358979需要等到ZxcvAsdfQwer_123654登录后再su过去,而root直接被锁了。
CentOS用户名,可以使用大写字母、小写字母、数字和减号、下划线。
ubuntu用户名,不可以使用大写字母,可以使用小写字母、数字、减号和下划线。
[此贴子已经被作者于2019-3-5 00:12编辑过]