本文提供兩種方法實現在MacOS上的Ubuntu GUI(圖形界面)顯示。
方法一功能更加強大,但是界面相對卡頓一些,適合檢查性操作,比如剛入門的小白還不太習慣通過命令終端去執行操作,就可以用這種方法作為輔助。
方法二更加輕量,可以實現服務器端單個應用的GUI到主機上的映射(比如打開jupyter notebook、pycharm),對GUI界面操作時很流暢。
方法一:借助VNC軟件
可以實現整個Ubuntu系統界面的顯示,具體請參考:博客中VNC部分。
方法二:借助X11(XQuartz)
step1:配置遠程服務器
安裝服務器上的X11
sudo apt-get install xorg
sudo apt-get install openbox
取消ssh_config文件中ForwardX11 yes
的注釋
sudo vim /etc/ssh/ssh_config
Host *
# ForwardAgent no
ForwardX11 yes
# ForwardX11Trusted yes
# RhostsRSAAuthentication no
保存退出,並重啟服務器的ssh服務
sudo /etc/init.d/ssh restart
step2:配置本機(MacOS)
安裝XQuartz
安裝完成后,同樣對ssh_config進行修改。
sudo vim /etc/ssh/ssh_config
修改如下(僅修改這部分就可,別都改了):
# Host *
# ForwardAgent no
# ForwardX11 yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# BatchMode no
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
# Protocol 2
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
# RekeyLimit 1G 1h
Host *
SendEnv LANG LC_*
ForwardX11 yes
step3:測試
登陸服務器
ssh -X username@host
cd到pycharm的bin目錄,輸入
./pycharm.sh # 啟動pycharm
截圖效果如下(不知為何截圖后成了這樣):
實際效果:

參考:
ubuntu端pycharm永久激活
自取: https://pan.baidu.com/s/166DQ_BHmF5PWfAyjbBhJjA 密碼: apac