Run SSH In The background After Running a GUI Linux Application

Posted on in Categories , , , , last updated June 11, 2014

How can I run ssh (or gui over ssh) in the background after running a Linux or Unix GUI application? How do I run any UNIX x11 application in background with SSH Linux client?

You need to use ssh X forwarding feature. This is default feature of OpenSSH ssh client. All you have to do is run command as follows:

ssh {[email protected]} -f -X {app-name}

OR

ssh -f -X {[email protected]} {/path/to/app-name} -arg1 -arg2

OR speed up with compression of all data:

ssh -f -X -C {[email protected]} {/path/to/app-name}

Where,

  • [email protected] : Your remote login username and password
  • -f : Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background. This is the recommended way to start X11 programs at a remote site/host.
  • -X : Enables X11 forwarding.
  • -C : Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11 and TCP connections).
  • -c cipher : Selects the cipher specification for encrypting the session.
  • -T : Disable pseudo-tty allocation.

Example: Run ssh in the background

For example run xterm (x windows terminal) or xeyes app as follows and go into background, enter:
$ ssh [email protected] -f -X xeyes
$ ssh [email protected] -f -X xterms
$ ssh [email protected] -f -X /opt/firefox/firefox

Tip: Speeding up slow links over ssh with compression

If you think that programs are running slowly because of a lack of bandwidth or network congestion, you can turn SSH compression by passing the -C option as follows:
$ ssh [email protected] -f -X -C xeyes
$ ssh -fXC [email protected] xterms
$ ssh -fXCT [email protected] /opt/firefox/firefox
## Set ciphers. Blowfish is a fast block cipher; it appears very secure and is much faster than 3des ##
$ ssh -f -X -C -c blowfish-cbc,arcfour [email protected] /path/to/raid-config-app

See also
  • Man pages – ssh(1), ssh_config(5),sshd(8)

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

Leave a Comment