Start a GUI Application as Current User over SSH
Thu, 02/28/2008 - 20:46 — Ross PeoplesWhile working on a project, my girlfriend, who was on the couch surfing the web, asked me for the address of something I found on the web. At the time I thought how helpful it would be to direct her browser right to the page instead of waiting for her to get on instant messaging and explaining how to copy and paste the URL into the browser. I snooped around with Google for a couple minutes and figured it out.
This method can be used for a number of things. The first one that comes to mind is helping a family member find the program they are looking for without bothering with VNC. Another reason could be to notify someone on the computer that you need to reboot it. There are a couple of requirements:
- The remote machine must be running an SSH server and it must be accessible
- You must have a user account on the remote machine with sudo ability
- You must know the username of the person currently logged in to the remote machine
If all those requirements are met, you can continue:
- Log in using SSH to the remote machine
- Enter this command (replacing username with the username of the person currently on the remote computer): sudo su username
- Enter this command (replacing command with the command you want to run): DISPLAY=:0 command
That's it! Now, you will most likely want to follow the command with an ampersand (&). This will return you back to the terminal once you run the command. Otherwise, you will have to wait until the command finishes before you will be able to use the terminal again.
So, to open the remote browser to the site, I would have entered: DISPLAY=:0 firefox "http://www.google.com" &
Very cool!
