How do I run a program in a remote computer with SSH ?

Posted on 2006-05-23
Last Modified: 2013-12-16
I am able to connect though SSH with a remote computer. Once I am connected, then I can create a new folder in the remote computer, I can also delete the folder in the remote computer, and so on...

I would like to be able to start a program in the remote computer as well. I do not want to see this program in my scree, I just want that program to start running in the remote computer.

How do I do this ?
Question by:probine
    LVL 2

    Expert Comment

    If the program executible is in your $PATH (echo $PATH), then you can simply type the program name followed by the ampersand.  For example, let's say I wanted to run or start mysqld_safe.  I'd type (this example is done as root):

    > # mysqld_safe &

    If the program does not reside in any of your $PATH directories, you can change directories to where it is as follows:

    > # cd /path/to/directory/

    Let's say I'm wanting to start a program named stats, in the /usr/local/stats/bin folder, but /usr/local/stats/bin isn't in my $PATH.  I can:

    > # cd /usr/local/stats/bin

    Then I can type:

    > # ./stats &

    Notice the period before the program name.

    You can also run the same program directly from your current location by typing:

    /usr/local/stats/bin/stats &

    Doing it this way, you don't need the preceeding period.

    Hope this helps.

    Author Comment

    Thanks for the detailed explanation, though it doesn't work in my computer.

    Computer A wants to run a program in computer B through SSH. I have looged into computer B, and I am able to create a folder, delete it, even to start and stop services, but:

    In computer A I typed:
    firefox &

    This command did not open firefox in computer B. The only thing it printed in the screen is: [1] 2339

    Help !!!
    LVL 2

    Expert Comment

    Ah, that's different.  Using ssh, you can start services, but you can't start what would otherwise be a gui program in the background for the remote user to see that way.

    When ssh'd in, if you try to load something that is a user level program, the system will try to present it to YOU.  Since you do not have a gui presence with an ssh, and since you have backgrounded it, there really is no place to go with the resulting program, so it just sits there in limbo (zombied).

    What exactly is it you are wanting to do?


    Author Comment

    I just want to be able to start firefox in the remote computer... I do not want to see it, only start it, so the remote user can see it.

    The problem I have is that in KDE the "kicker" or menu bar ( where you start the programs, clock, etc...) disappeard in the remote computer, so I want to make it appear again.
    LVL 2

    Expert Comment

    I don't believe it's possible for you to remotely open a program that will appear on the end users desktop.  If it is, I've never heard of it.



    Author Comment

    Hi CapTech,

    It is not that I do or don't believe on it. It is a question that I would like to solve fro curiosity.

    Machine A wans to open firrefox in Machine B. how?

    Expert Comment

    have you tried to redirect the display to machine B? What you should type on the shell (on the remote machine) is just the following command:
    export DISPLAY=:0
    After doing that, firefox should open on machine B.
    LVL 22

    Accepted Solution

    In think that I understand what you are trying to do. The problem that you have here is that in order to run Firefox, you must have an X server running providing a suitable the remote machine run:


    It will automatically daemonise and run in the background, so you do not need the & already mentioned. You will be asked for a password to allow vnc connections

    You can then connect from your local machine using vncclient.

    If you want a 'nice' kde or gnome desktop, then you'll need to edit the


    before connecting to be:

    # Uncomment the following two lines for normal desktop:
    exec /etc/X11/xinit/xinitrc

    Now start up a remote shell on the remote system, and you can run firefox, or anything else that you want.

    Useful bits of info:

    1.   To kill a vncserver:

    vncserver -kill :1

    where 1 is the display number

    2.    To check whether firefox exists on the remote computer:

    which firefox

    should give the path.

    3.    Web site for vnc:

    if you need to download a windows client for it.

    Consider that vnc just enables you view what is running in a session on the remote machine. Once you have disconnected, everything carries on running, and you can reconnect and see how far it has got at a later date.

    More complex solutions are available, such as NX:

    if you decide that you really like this concept at a later date.


    LVL 22

    Expert Comment

    If your user wants you to be able to connect to them, then there is a variant of vncserver that they can run called:


    which connects their desktop to a vnc server, and means that you can connect to them remotely in order to assist.

    (   (()
    (`-' _\
     ''  ''

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now