阿里云CentOS服务器更改ssh端口
# 背景
自从搞了个博客网站后,老是有人想通过ssh登陆我的服务器。就下边这些IP(第三列)全都是。
[test@aliyun ~]# lastb
rooasdad ssh:notty 106.37.187.193 Wed Jul 8 11:20 - 11:20 (00:00)
rooasdad ssh:notty 106.37.187.193 Wed Jul 8 11:20 - 11:20 (00:00)
admin ssh:notty 109.94.52.93 Wed Jul 8 11:16 - 11:16 (00:00)
admin ssh:notty 109.94.52.93 Wed Jul 8 11:16 - 11:16 (00:00)
admin ssh:notty 113.173.16.100 Wed Jul 8 11:16 - 11:16 (00:00)
admin ssh:notty 113.173.16.100 Wed Jul 8 11:16 - 11:16 (00:00)
root ssh:notty 106.37.187.193 Wed Jul 8 11:10 - 11:10 (00:00)
root ssh:notty 106.37.187.193 Wed Jul 8 11:09 - 11:09 (00:00)
guest ssh:notty 189.143.95.100 Wed Jul 8 02:38 - 02:38 (00:00)
guest ssh:notty 189.143.95.100 Wed Jul 8 02:38 - 02:38 (00:00)
cirros ssh:notty 96.28.161.249 Tue Jul 7 08:51 - 08:51 (00:00)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
也不知道是何居心,所以干脆就把端口给改了,一了百了。
# 操作步骤
- 去阿里云控制台配置安全组规则,新增一套规则,端口使用
10086
(端口号随意,尽量1024以上)。 - 登陆服务器,编辑文件
/etc/ssh/sshd_config
vim /etc/ssh/sshd_config
1
取消 #Port 22
的注释,在下一行添加你需要修改的新端口Port 10086
。这里不删除22
端口是为了防止修改后新端口无法访问,造成无法用 ssh 连接服务器。修改后保存并退出。
- 重启
sshd
服务:
systemctl restart sshd
1
- 关闭防火墙
# Centos7 使用以下命令
systemctl stop firewalld.service
# 永久禁用防火墙
systemctl disable firewalld.service
1
2
3
4
2
3
4
- 用 ss 命令检查 ssh 监听的端口是否有
10086
ss -tnlp | grep sshd
1
有10086
这个端口的话,就继续编辑/etc/ssh/sshd_config
文件,将之前的22
端口号注释掉,然后保存,再次重启sshd
服务就可以了。
- 使用ssh连接服务器
ssh -p 10086 用户名名@服务器IP或域名
1
编辑 (opens new window)
上次更新: 2023/01/04, 02:34:17
- 01
- Python实现对字符串的加解密02-25
- 02
- Python3对大文件中指定字符进行排序再写入到新的文件10-24
- 03
- Ubuntu下配置adb环境连接Android设备进行调试08-17