终端操作
使用ssh-keygen命令创建密钥,会在~/.ssh/目录下会生成两个文件id_rsa-remote-ssh和id_rsa-remote-ssh.pub。ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa-remote-ssh
拷贝公钥
pbcopy < ~/.ssh/id_rsa-remote-ssh.pub
ssh登陆远程服务器
ssh user@host
创建/修改authorized_keys文件
vim .ssh/authorized_keys
将刚刚 pbcopy 命令拷贝的内容粘贴到 authorized_keys 里并保存去掉 /etc/ssh/sshd_config 中 PubkeyAuthentication 前的 # 号重启远程服务器的ssh服务
systemctl restart sshd.service
vscode Remote-SSH插件配置
可以直接从vscode的扩展中下载,下载完成后左侧会出现Remote Explorer图标。创建配置文件/Users/your-host-name/.ssh/config
并填入
Host xxx # xxx 自定义连接名称User xxxx # root 远程服务器账户名称HostName xxx.xxx.xxx.xxx # 远程服务器地址IdentityFile ~/.ssh/id_rsa-remote-ssh.pub # 本地密钥所在位置
点进Remote Explorer即可
参考
https://qlzhu.github.io/blog/15892/