我更改了/etc/ssh/sshd_config文件中的SSH 端口,然后重新启动了 ssh 服务。我实现了 fail2ban 并在该配置下将端口更新到我的 SSH。然后我还实施了 UFW 防火墙并允许传入连接到我的新 SSH 端口。
但是,当我尝试使用我的 SSH 密钥登录时,ssh -i /Users/myuser/.ssh/vpsssh user@555.555.555.555它试图连接到端口 22 而不是我拥有的定义端口。
ste*_*ver 27
您可以ssh使用该-p选项在客户端命令行上指定非默认端口。来自man ssh:
-p port
Port to connect to on the remote host. This can be specified on
a per-host basis in the configuration file.
Run Code Online (Sandbox Code Playgroud)
您可能希望将主机的端口号和身份文件位置都放在一个~/.ssh/config文件中,这样就不需要每次在命令行上都指定它们。
前任。
Host myremotehost
Hostname 555.555.555.555
User user
Port 20002
IdentityFile /Users/myuser/.ssh/vpsssh
Run Code Online (Sandbox Code Playgroud)
然后你将能够使用:
ssh myremotehost
Run Code Online (Sandbox Code Playgroud)
请注意,ssh接受 URI 形式的命令,例如ssh://user@host.com:<port>. 基于此,我在使用私钥登录远程服务器时所做的如下:
ssh -i ~/.ssh/id_rsa ssh://myuser@domain_name.com:2222
Run Code Online (Sandbox Code Playgroud)