我正在测试Google Compute Engine,我使用Ubuntu OS创建了一个VM。当我连接到它时,通过单击 Connect SSH 按钮,它将打开一个控制台窗口。
这是你得到的联系吗?
如何打开带有GUI的真实屏幕?我不想要控制台。
答案 0 :(得分:7)
Google自己提供了更好的解决方案:
https://medium.com/google-cloud/linux-gui-on-the-google-cloud-platform-800719ab27c5
答案 1 :(得分:5)
您需要将X11会话从VM转发到本地计算机。这在Unix和Linux堆栈站点中已经介绍过:
https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-from-ubuntu-machine
由于您要连接到预期运行计算任务的服务器,因此可能没有安装X11服务器。您可能需要安装X11和类似的。您可以按照此处的说明执行此操作:
https://help.ubuntu.com/community/ServerGUI
由于我最近需要这样做,我将简要地在此处写下所需的更改:
配置服务器
$ sudo vim /etc/ssh/sshd_config
确保X11Forwarding yes
存在。如果更改设置,请重新启动ssh守护程序:
$ sudo /etc/init.d/sshd restart
配置客户端
$ vim ~/.ssh/config
确保主机存在ForwardX11 yes
。例如:
Host example.com
ForwardX11 yes
转发X11
$ ssh -X -C example.com
...
$ gedit example.txt
受信任的X11转发
如果应用程序遇到不受信任的转发问题,您可能希望启用可信转发。
您可以使用ForwardX11Trusted yes
文件中的~/.ssh/config
永久启用此功能。
您可以使用-Y
参数代替-X
参数为单个连接启用此功能。
答案 2 :(得分:4)
gcloud compute --project "project_name" ssh --zone "project_zone" "instance_name"
sudo apt update && sudo apt upgrade
sudo apt-get install xorg lxde vnc4server
vncserver
sudo echo "lxpanel & /usr/bin/lxsession -s LXDE &" >> ~/.vnc/xstartup
sudo reboot
cloudshell download-files $HOME/.ssh/google_compute_engine
ssh -L 5901:localhost:5901 -i "google_compute_engine" username@instance_external_ip -v -4
vncserver -geometry 1280x800
localhost:5901
,将协议设置为VNC
注1:检查vncserver是否正常工作正常使用:
netstat -na | grep '[:.]5901'
tail -f /home/user_id/.vnc/instance-1:1.log
注2:重启vncserver使用:
sudo vncserver -kill :1 && vncserver
*****首次通过Google云端口连接时,公钥和私钥会自动生成并存储在$HOME/.ssh/
ls $HOME/.ssh/
google_compute_engine google_compute_engine.pub google_compute_known_hosts
公钥应添加到home/*user_id*/.ssh/authorized_keys
在VM实例中(当您首次从Google云外壳SHH到VM实例时自动完成此操作,即在步骤2中)
您可以在实例元数据中确认这一点
答案 3 :(得分:1)
Chrome远程桌面允许您使用图形用户界面从本地计算机或移动设备远程访问应用程序。使用这种方法,您无需打开防火墙端口,而使用Google帐户进行身份验证和授权。
查看此Google教程以将其与Compute Engine结合使用:https://cloud.google.com/solutions/chrome-desktop-remote-on-compute-engine