树莓派ubuntu:vscode remote-ssh免密登录(Mac)

Vscode remove-ssh远程开发很方便,但是每次登陆都会频繁要求输入密码,使用期间也会多次断开重连,提示再次输入密码。

可能因为我开发板的ubuntu系统用的后来创建的用户的原因,按网上的文章始终无法实现免密登录,多次尝试后如下方式解决,整理如下:

1. 本地生成key

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa-remote-ssh

生成的文件在/Users/xxx/.ssh下

2. 创建目录

mkdir /home/用户名/.ssh/

3. 上传key到用户名录的.ssh下,文件名必须为authorized_keys

scp /Users/xxx/.ssh/id_rsa-remote-ssh.pub  [email protected]:/home/用户名/.ssh/authorized_keys

4. linux中权限设置

cd /home/用户名/.ssh
sudo chmod 600 authorized_keys
sudo chmod 700 ~/.ssh

5. 开启配置/etc/ssh/sshd_config中

RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication no

6. 重启服务

service sshd restart

如果有多个用户可能会提示你选择用户,选择之前放置authorized_keys的用户

7. Vscode remote-ssh中设置

/Users/用户/.ssh/config mac下配置文件在这里

Host 192.168.43.141
  HostName 192.168.43.141
  User 用户名
  IdentityFile "~/.ssh/id_rsa-remote-ssh"

用户名自行修改,IdentityFile对应私钥文件

8. 重启Vscode测试免密登录

猜你喜欢

转载自blog.csdn.net/zhbzhb324/article/details/135565907