linux服务器修改ssh默认22端口方法
今天ssh登录时偶然发现root密码登录后提示:
Last failed login: Fri Dec 15 10:41:37 CST 2017 from 51.15.220.221 on ssh:notty
There were 49 failed login attempts since the last successful login.
明显被攻击了,改端口,走起!
1、登录服务器,打开sshd_config文件
# vim /etc/ssh/sshd_config
2、找到#Port 22,默认是注释掉的,先把前面的#号去掉,再插入一行设置成你想要的端口号,注意不要跟现有端口号重复
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
Port 22
Port 26580
3、保存后退出,执行重启命令
# /etc/init.d/sshd restart or systemctl restart sshd.service
4、新开一个终端窗口测试23456端口是否可以正常连接服务器,如果成功则将Port 22删除,之所以先设置成两个端口,测试成功后再关闭一个端口,是为了方式在修改conf的过程中,万一出现掉线、断网、误操作等未知情况时候,还能通过另外一个端口连接上去调试以免发生连接不上必须派人去机房,导致问题更加复杂麻烦。