This article is probably not only for absolutely beginners, so many Linux guys do not know they can just execute a GUI program on their remote machine but the output of the graphics to be drawn in the local display, it’s like your local display is connected to the remote computer through the network. And you do not need any special software like VNC Client/Server, TeamViewer – all you need is the OpenSSH package you probably have when managing a remote machine. And it is absolutely secure, because all the communication is performed within ssh.
Suppose you have a machine, which have some GUI capabilities (you know if we speak for servers not all servers need the GUI, but in some cases we need it) and you want to execute a graphical program on the remote.
Here is how you can login to be sure you can execute the program remotely:
ssh -o ForwardX11=yes -o ForwardAgent=yes -o ForwardX11Trusted=yes [USER]@[IP]
And you can also execute a remote command with the ssh:
ssh -o ForwardX11=yes -o ForwardAgent=yes -o ForwardX11Trusted=yes firstname.lastname@example.org 'virtualbox'
This command will execute virtualbox on your remote machine with login email@example.com and the output the display on your local machine.
Here are some examples. Gentoo Desktop using KDE with konsole get to the remote machine on out local network 198.160.245:
SCREENSHOT 1) Login in your remote machine and there type firefox. The firefox will be executed on the remote machine, but the graphics will be outputed on your local display.
SCREENSHOT 2) Login in your remote machine and there type virtualbox. The VirtualBox will be exeucted on the remote machine. You can see we started a virtual machine in our virtualbox program.
SCREENSHOT 3) While still logged in the remote machine you can execute gnome and even native gnome programs. Here we executed the Gnome Software center. You may install a programe and it will be installed on the remote machine.
SCREENSHOT 4) nautilus started and you can manage your files.
You may encounter an error similar to:
No xauth program.
You should install xauth on the server:
apt install xauth
- CentOS 7
yum install xorg-x11-xauth
emerge -va x11-apps/xauth
* Bonus – set ssh configuration
Of course you can set these options in your client ssh configuration file in “~/.ssh/config”.
Create a file “~/.ssh/config” and put these configs:
mkdir -p ~/.ssh/ chmod 700 ~/.ssh touch ~/.ssh/config echo <<< EOL Host rexec 192.168.0.245 HostName 192.168.0.245 Port 22 User myuser ForwardX11=yes ForwardAgent=yes ForwardX11Trusted=yes # IdentityFile ~/.ssh/personal-ident EOL >> ~/.ssh/config
You could uncomment the IdentityFile if you set to use keys for password-less login. (Beyond the scope of this article).
And then you could just type in your local console OR in your favorite GUI->run command, or even you can create a menu item to execute command (so next time you just click with the mouse on the icon in your Desktop/menu) like this:
ssh rexec virtualbox
To execute remotely virtualbox and to show the graphics on your local display.