Linux云服务器防止被黑

2022-03-03  本文已影响0人  Ocean_e553

最近买了一台云服务器玩, 每次ssh登录root账户都发现有很多尝试登录的请求, 由于云服务器上没有什么重要内容, 所以没在意, 还想看看服务器多久会被黑, 结果今天就悲剧了, root账户登不上了...

l@OceandeMac ~ % ssh root@x.x.x.x
root@x.x.x.x's password: 
Activate the web console with: systemctl enable --now cockpit.socket

Last failed login: Thu Mar  3 14:29:40 CST 2022 from 115.146.182.x on ssh:notty
There were 426 failed login attempts since the last successful login.
Last login: Thu Mar  3 10:21:24 2022 from 113.57.x.x
l@OceandeMac ~ % ssh root@x.x.x.x
root@x.x.x.x's password: 
Permission denied, please try again.
root@x.x.x.x's password: 
Permission denied, please try again.
root@x.x.x.x's password: 

所以必须重置系统, 然后做一些安全措施了!

主要有两种方式:
1.禁用密码登录, 改用密钥登录的方式.
2.创建一个新用户并给予root权限, 禁用掉root用户的密码登录方式, 以后要登录的时候使用自定义的用户进行登录

这里选择第2种方式进行处理, 步骤如下:

1.使用root用户登录服务器, 创建新用户

useradd ocean  #添加用户名为ocean的用户

2.设置用户ocean的登录密码

passwd ocean  # 然后设置登录密码, 并确认密码

3.给用户ocean赋予root权限

修改/etc/sudoers文件,找到下面一行,
## Allow root to run any commands anywhere 
root ALL=(ALL) ALL
在root下面添加一行,如下所示:
ocean ALL=(ALL) ALL

4.修改SSHD配置,禁用root登录

vi /etc/ssh/sshd_config

找到“PermitRootLogin yes”把后面的yes改成no。

5.重启SSHD服务

service sshd restart

6.下次登陆的时候先用ocean用户登录,如果需要切换到root用户, 使用su root切换即可

su root  #回车会提示输入密码,输入root密码即可切换到root权限
上一篇下一篇

猜你喜欢

热点阅读