SSH 连接服务器时指定私钥的路径

使用 Visual Studio CodeRemote - SSH 插件连接服务器开发时,有可能会遇到不同的服务器对应不同的私钥的情况,这时就需要单独为各个服务器指定私钥的位置。打开 SSH 配置文件(默认路径是 ~/.ssh/config),在需要指定私钥路径的服务器下添加 IdentityFile path-to-private-key 即可,例如:

1
2
3
4
5
Host your-host
HostName your-host-name
User your-host-user
ForwardAgent yes
IdentityFile path-to-private-key

参考: