Run SSH In The background After Running a GUI Linux Application

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:

ADVERTISEMENTS

ssh {user@server-ip} -f -X {app-name}[donotprint]

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
RequirementsOpenSSH ssh client/server
Time2m
[/donotprint]

OR

ssh -f -X {user@server-ip} {/path/to/app-name} -arg1 -arg2

OR speed up with compression of all data:

ssh -f -X -C {user@server-ip} {/path/to/app-name}

Where,

  • user@server-ip : 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 vivek@d1.vpn.nixcraft.in -f -X xeyes
$ ssh vivek@d1.vpn.nixcraft.in -f -X xterms
$ ssh vivek@d1.vpn.nixcraft.in -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 vivek@d1.vpn.nixcraft.in -f -X -C xeyes
$ ssh -fXC vivek@d1.vpn.nixcraft.in xterms
$ ssh -fXCT vivek@d1.vpn.nixcraft.in /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 vivek@www544.nixcraft.net /path/to/raid-config-app

See also
  • Man pages – sshd(8)
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one
  • Tom Jun 11, 2014 @ 10:04

    Thanks for this tip. I was struggling to find a way to fun a remote x11 application in the background. The ‘-f’ flag was the key

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.