1.两台电脑都安装openssh-server和openssh-client。
sudo apt install
2.查看ssh服务是否启动。
ps -e | grep ssh
如果显示有sshd
的选项,即代表启动成功。
如果没有,可通过如下命令启动
sudo
3.1 如果只是在纯终端方式下开发,直接通过
ssh username@ip, 例如 ssh
命令登录服务机即可。
3.2 如果需要在客户端显示服务端的一些GUI界面,比如gedit、pybullet的窗口等,需要一些额外的操作,即打开X11Forward功能。
3.2.1 在服务器端,打开X11Forward功能
sudo vi
取消X11Forwarding yes
那行的注释,如第89行所示。
3.2.2 在服务器端,添加一个~/.Xauthority文件
mv ~/.Xauthority ~/.Xauthority.bak
vi
添加如下内容到内:
# only this one key is needed for X11 over SSH
xauth generate :0 . trusted
# generate our own key, xauth requires 128 bit hex encoding
xauth add ${HOST}:0 . $(xxd -l 16 -p /dev/urandom)
# To view a listing of the .Xauthority file, enter the following
3.2.3 在客户端,打开X11Forwording功能
sudo vi
取消注释AllowAgentForwarding yes, X11Forwarding yes
两项。
3.2.4 登录服务器
ssh -X username@ip,例如 ssh
注意多加了一个-X
参数。
此时在服务器端终端中输入gedit
,打开的GUI界面会显示在客户端的电脑上。
参考
- Ubuntu下使用SSH可视化
- xauth not creating .Xauthority file