使用更改后的 SSH 端口使用 SSH 授权密钥登录

使用更改后的 SSH 端口使用 SSH 授权密钥登录

我在/etc/ssh/sshd_config文件中更改了我的 SSH 端口,然后重新启动了 ssh 服务。我实施了 fail2ban 并在该配置下将端口更新为我的 SSH。然后,我还实施了 UFW 防火墙并允许传入连接到我的新 SSH 端口。

但是,当我尝试使用我的 SSH 密钥登录时,它会尝试连接到端口 22,而不是我定义的端口。ssh -i /Users/myuser/.ssh/vpsssh [email protected]

答案1

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.

您可能希望将主机的端口号和标识文件位置都放在一个~/.ssh/config文件中,这样就不需要每次在命令行上指定它们。

前任。

Host myremotehost
  Hostname      555.555.555.555
  User          user
  Port          20002
  IdentityFile  /Users/myuser/.ssh/vpsssh

然后您将能够使用:

ssh myremotehost

答案2

注意ssh接受URI形式的命令,例如。基于此,我使用私钥登录远程服务器时所做的操作如下:ssh://[email protected]:<port>

ssh -i ~/.ssh/id_rsa ssh://myuser@domain_name.com:2222

相关内容