Running graphical commands on a remote machine
If you attempt to run a command on a remote machine that uses a graphical window, you will see an error similar to cannot open display
. This is because the ssh
shell is attempting (and failing) to connect to the X server on the remote machine.
How to do it...
To run an graphical application on a remote server, you need to set the $DISPLAY
variable to force the application to connect to the X server on your local machine:
ssh user@host "export DISPLAY=:0 ; command1; command2"""
This will launch the graphical output on the remote machine.
If you want to show the graphical output on your local machine, use SSH's X11 forwarding option:
ssh -X user@host "command1; command2"
This will run the commands on the remote machine, but it will display graphics on your machine.
See also
- The Password-less auto-login with SSH recipe in this chapter explains how to configure auto-login to execute commands without prompting for a password