ubuntu 本地平台 vscode remote-ssh 连接远程服务器 免密登录

几个月没用VS Code远程连接服务器,连不上了。重新折腾一番,记录如下:

1. 安装 Remote-SSH 插件

参考:【Ubuntu下安装vscode并实现免密远程连接服务器】
配置 ~/.ssh/config 文件。只需要点击远程资源管理器图标,找到 加号 + add new,输入 ssh name@host-id .
接下来频繁输入密码。。。

所以我们来研究一下免密登录:

2. SSH KEY 配置

如果没有密钥,请在本地终端中运行以下命令以生成SSH密钥对:

sh-keygen -t rsa -b 4096

授权你的Linux机器进行连接。在本地终端窗口中运行以下命令,以将本地公共密钥复制到SSH服务器。
Connecting to a macOS or Linux SSH host:

export USER_AT_HOST="your-user-name-on-host@hostname"
export PUBKEYPATH="$HOME/.ssh/id_rsa.pub"
ssh-copy-id -i "$PUBKEYPATH" "$USER_AT_HOST"

这样就可以不用输入密码登录了。

参考: vscode 官方教程——Remote Development Tips and Tricks

Set up SSH public-key authentication to connect to a remote system

3. debug

【VS Code | SSH Remote】免密登录时提示enter passphrase for key ‘~/.ssh/id_rsa’

需要输入三次密码才能登录。

原因是第一次生成key时,面对陌生的命令,莫名其妙就设置了密码,然后每次使用时都需要输入密码这个繁杂的操作。

解决方法:

$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]

例如

$ ssh-keygen -p -P 123456 -N '' -f ~/.ssh/id_rsa

这样就把最开始设置的’123456’密码改为了万能的’'密码了。

【VS Code | SSH Remote】failed to create hard link ‘/home//.vscode-server/bin//*’ file exists

解决方法
删除对应硬链接 /home/usrname/.vscode-server/bin/…filename/ 下的两个文件:

vscode-remote-lock.一串乱码数字.
vscode-remote-lock.一串乱码数字.target

参考:【VS Code | SSH Remote】failed to create hard link ‘/home//.vscode-server/bin//*’ file exists

猜你喜欢

转载自blog.csdn.net/zxxxiazai/article/details/106409533