vscode ssh 秘钥连接

822 阅读1分钟

官网教程:code.visualstudio.com/docs/remote…

生成秘钥

ssh-keygen -t rsa -b 2048

按下回车后显示如图,输入密码,可按回车跳过。设置密码后每次使用秘钥连接还是要输入密码:

image.png

cd ~/.ssh
# 可以输入不同的公钥到同一个 authorized_keys 文件中,这样可以用不同私钥链接
cat id_rsa.pub >> authorized_keys

编辑 /etc/ssh/sshd_config 文件,进行如下设置

RSAAuthentication yes
PubkeyAuthentication yes

另外,请留意 root 用户能否通过 SSH 登录:

PermitRootLogin yes

当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:

PasswordAuthentication no

最后,重启 SSH 服务:

[root@host .ssh]$ service sshd restart

VScode 配置

安装插件 Remote - SSH

image.png

在配置文件中输入

image.png

Host 测试服务器
    HostName 124.xx.xx.69
    User root
    IdentityFile C:\\Users\\BY\\.ssh\\id_rsa