无法更改ssh端口| 服务器16.04
我想将ssh端口从22更改为2800 。 我尝试更改/etc/ssh/ssh_config
并从端口线中删除#并将数字更改为2800 。 触发命令后: service ssh restart
连接继续。 当我尝试从端口2800连接时,它拒绝了。 /etc/ssh/ssh_config
是: 删除了注释行
Host * Port 2800 SendEnv LANG LC_* HashKnownHosts yes GSSAPIAuthentication yes GSSAPIDelegateCredentials no
命令service ssh status
提供以下输出:
● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2017-09-22 20:31:45 IRST; 1s ago Main PID: 1825 (sshd) Tasks: 1 Memory: 724.0K CPU: 5ms CGroup: /system.slice/ssh.service └─1825 /usr/sbin/sshd -D Sep 22 20:31:45 GoodMind systemd[1]: Starting OpenBSD Secure Shell server... Sep 22 20:31:45 GoodMind sshd[1825]: Server listening on 0.0.0.0 port 22. Sep 22 20:31:45 GoodMind sshd[1825]: Server listening on :: port 22. Sep 22 20:31:45 GoodMind systemd[1]: Started OpenBSD Secure Shell server.
我也尝试了其他端口。 但它仍然具有相同的地位。 我做错了什么?
更改ssh端口不在/etc/ssh/ssh_config
文件中,而是在/etc/ssh/sshd_config
(在ssh之后你想念“守护进程”)。
只需编辑此更改并更改取消注释并更新该行
#Port 22
在service ssh restart
不要忘记重新启动服务。
您的设置是正确的,但您在错误的配置文件中更改了它们。 它应该是/etc/ssh/sshd_config
,您可能需要重新启动SSH服务并打开SSH服务器正在侦听的新端口。
为此,请运行以下命令:
-
sudo service ssh restart
或sudo systemctl restart sshd.service
- 打开防火墙上的端口
sudo iptables -I INPUT -p tcp --dport 2800 -j ACCEPT
。
这应该是您在端口2800
上接受连接所需的全部内容。 您还可以使用netstat -lt4
检查您的计算机正在侦听的端口,您应该看到类似的行
tcp 0 0 *:2800 *:* LISTEN
请让我知道这对你有没有用!