vscode SSH 保存密码自动登录服务器

2020-07-15  本文已影响0人  旭日丶丶
  1. 本地生成RSA密钥, 参考: https://www.jianshu.com/p/09b81c07e03f
  2. 输入(多个用户登录输入多次):
ssh-copy-id -i ~/.ssh/id_rsa.pub username@192.168.2.22

则会提示:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/username/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
username@192.168.2.22's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'username@192.168.2.22'"
and check to make sure that only the key(s) you wanted were added.
  1. 然后你登录服务器就会自动登录了
ssh username@192.168.2.22
  1. 这时候在vscode中安装好Remote-SSH插件, 点击vscode左下角绿色箭头打开远程连接, 选择open configuration file, 输入:
Host 2.22_username
  HostName 192.168.2.22
  User username
  PreferredAuthentications publickey
  IdentityFile "/Users/username/.ssh/id_rsa"

Host 2.22_username2
  HostName 192.168.2.22
  User username2
  PreferredAuthentications publickey
  IdentityFile "/Users/username/.ssh/id_rsa"

保存后, 再次用vscode登录即可

上一篇下一篇

猜你喜欢

热点阅读