vscode ssh 免密登录

  1. 需要关闭密码;好像密码登录会优先于rsa
  2. 要开启RSA,以及授权authorized_keys文件 
  3. 要在服务器端执行这个:sudo chmod 600 authorized_keys # 这个要执行  
  4. 多个key要这样写: AuthenticationFile .ssh/authorized_keys_pc .ssh/authorized_keys_homePC
# ----------------------------------------------------
# 1. 本地电脑VS Code安装插件 Remote Development
# 在本地电脑.ssh目录下生成公钥(id_rsa.pub)和私钥(id_rsa)
cd ~/.ssh
ssh-keygen
# 生成公钥和私钥,添加公钥authorized_keys,并复制到服务器上
cat id_rsa.pub >> authorized_keys # 这一步在windows上会失败;windows上将id_rsa.pub重命名为authorized_keys 并去掉后缀.pub即可,记事本打开里面要有内容

ls  # =>查看确保生成功authorized_keys
scp authorized_keys name@server_ip:/home/name/.ssh
#-----------------------------------------------------
# 2.在服务器上更改私钥权限。打开SSH配置文件,禁用密码登陆(选项)。最后重启ssh服务
cd /home/name/.ssh
sudo chmod 600 authorized_keys
sudo chmod 700 ~/.ssh

sudo nano /etc/ssh/sshd_config
"RSAAuthentication yes
 PubkeyAuthentication yes
 PasswordAuthentication no"

service sshd restart

#-----------------------------------------------------
# 3. 本地电脑vscode配置文件修改
# 最后修改本机电脑配置ssh文件 vscode的ssh配置那里把密钥文件也一起写上
Host name
  HostName ip
  User username
  IdentityFile /path/.ssh/id_rsa
Host 169.254.xxx.xxx
  HostName 169.254.xxx.xxx
  User zhr
  IdentityFile c:/Users/xxxx/.ssh/id_rsa # 注意这里windows的写法
  ForwardX11 yes
  ForwardX11Trusted yes
  ForwardAgent yes

#------------------------bug解决-----------------------------
# 若提示“ Permissions 0644 for ‘/xx/.ssh/id_rsa.pub’ are too open”,使用以下指令更改私钥权限
chmod 0600 ~/.ssh/id_rsa
# 若提示“Enter passphrase for key”,执行下面代码
ssh-add -K ~/.ssh/id_rsa

# 若提示:permission denied (publickey)
sudo chmod 600 authorized_keys # 这个要执行(1)
sudo nano /etc/ssh/sshd_config
"RSAAuthentication yes # 这个忘记写了(2)
 PubkeyAuthentication yes
 PasswordAuthentication no"
 # (3)还添加了
 AuthenticationFile .ssh/authorized_keys_pc .ssh/authorized_keys_homePC # 最后才通过了,多个key要这样写才行

你可能感兴趣的:(vscode,ssh,ide)