目的:使用vs code ssh 远程连接树莓派上的share目录,由于share目录是由镜像挂载的,只有root用户有写的权限,因而还需要开通树莓派root登录功能。
- 开启root登录
>>> pi@raspberrypi:~ $ sudo passwd root
New password:
Retype new password:
passwd: password updated successfully
>>> pi@raspberrypi:~ $ sudo passwd --unlock root
passwd: password expiry information changed.
>>> pi@raspberrypi:~ $ sudo sed -i "s/^#PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
>>> pi@raspberrypi:~ $ sudo systemctl restart ssh
>>> pi@raspberrypi:~ $ sudo cp ~/.bashrc /root/.bashrc
- 无密码ssh登录
>>> ssh-keygen -t rsa
>>> ssh-copy-id -i ~/.ssh/id_rsa.pub root@xx.xx.xx.xx
- vs code连接
2019-10-10 更新
如果想要连接远程主机中的docker镜像,则需要做如下配置:
在上图中显示的VS code的config文件中修改:
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host Pi-00-Docker
HostName 10.8.15.51
User root
Port 8888
其中Port默认为22,我这里改成了8888
在远程的Docker镜像中配置:
# 安装ssh服务端
>>> apt install openssh-server
# 开启ssh服务
>>> /etc/init.d/ssh restart
# 设置root密码
>>> passwd root
# 修改sshd_config文件
>>> vim /etc/ssh/sshd_config
# 8888端口为映射的镜像端口
Port 8888
ListenAddress 0.0.0.0
PermitRootLogin yes
>>> service ssh restart
搞定!