Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to view (and control) a remote desktop through SSH? I will not have physical access to the remote host machine.

share|improve this question
add comment

3 Answers 3

up vote 12 down vote accepted

Method 1 :

This can be achieved with vino vnc server & remmina (both come default with ubuntu; if not install it by running sudo apt-get install remmina). Then Run Following commands from local computer in terminal prompt:

  1. ssh -Y gman@remote. Use trusted X11 forwarding, otherwise it wont work

  2. vino-preferences. It will open vino-preferences.

    vino-preference

  3. Also Click configure network automatically to accept connection. But don't enter any password, its base64 encoded. Then click close. Then run:

    sudo -s
    
    export DISPLAY=:0.0
    
    xhost +
    
    /usr/lib/vino/vino-server & 
    

    It will start the vino server.

  4. Logout from server:

    xhost -
    
    Press CTRL+C twice
    
    exit
    
    exit
    
  5. Then open remmina. Choose vnc under protocol.

    Under basic tab put server address in server field.

    On ssh tab click enable ssh tunnel. Under ssh authentication, it could be password or public key:

    remmina-preference

    Click save. And then double click connection-name(home-desktop as shown in the picture) to start browsing remote desktop.


Method 2:

x11vnc is a simple VNC server and you won't have to mess around with Gnome settings or 500 firewalls, just install x11vnc on all your computers (with puppet or whatever you're using for mass-control).

Then from your local computer run:

ssh user@host -L 5900:localhost:5900 "x11vnc -display :0 -noxdamage"

Obviously swapping user@host for the username and hostname/IP of the remote computer.

And then use a VNC client of your choice to connect to localhost:5900. The SSH command starts a vnc server on the remote computer and then tunnels back that port over SSH. You don't have to open up any ports (as long as you can already SSH).

If your computers have funny display settings, you might do better to leave off the -display :0 segment in the SSH command. x11vnc will then automatically try to find the right display.


Source: askubuntu

share|improve this answer
    
+1 for the ssh tunneling + x11vnc, which is ingenious! –  erik Feb 20 at 22:14
    
If you are using vncviewer with a slow ssh connection, your command should look like vncviewer localhost::5900 -viewonly -encodings "tight" -quality 0 (on Debian/Ubuntu the viewer is from tightvnc) or vncviewer localhost::5900 -viewonly -PreferredEncoding tight QualityLevel=0 (on Red Hat/Fedora the viewer is from tigervnc), where quality level on both Debian and Redhat is between 0 and 9, where 9 is best, but needs fast connection. –  erik Feb 24 at 9:26
    
@erik Thanks for explaining how to use it with vncviewer for slow connection. I personally, will probably set QualityLevel=4 or 5 because 0 qualitylevel (which is 256 colors, I think) is too dull for me. –  Khurshid Alam Feb 24 at 13:29
add comment
  1. You could use ssh to start a vnc session
  2. Use Xnest with X11 forwording to remotely start a session and forward it to your current computer. (I do this from time to time with my pi) man page

I use Xnest like so:

  • Xnest :1 -ac &
  • then DISPLAY=:1 . /etc/X11/Xsession
share|improve this answer
add comment

Overview of Solution

Assuming you have already setup an OpenSSH Server on your host machine, you must first enable desktop control on your host machine. If you can first enable desktop control on your host machine locally, head to 1a. If you must first enable desktop control on your host machine remotely, head to 1b.

Next create a Remote Desktop Client profile on your client machine in order to connect to the host machine through an SSH tunnel and ultimately view and control the host machine's desktop through an SSH tunnel.

1a. Locally Enable Remote Control of Host Machine

Do the following on the host machine:

vino-preferences
  • vino-preferences also in Dash under Desktop Sharing

enter image description here

  1. Tick Allow other users to view your desktop
  2. Tick Allow other users to control your desktop
  3. Tick Require the user to enter this password
  4. Enter a difficult to guess passphrase
  5. Close

1b. Remotely Enable Remote Control of Host Machine

Do the following on the client machine, replacing 123.123.12.3 with your host machine's IP address:

ssh -Y 123.123.12.3
  • -Y, Enables trusted X11 forwarding. Trusted X11 forwardings are not subjected to the X11 SECURITY extension controls.

vino-preferences
  • vino-preferences also in Dash under Desktop Sharing

enter image description here

  1. Tick Allow other users to view your desktop
  2. Tick Allow other users to control your desktop
  3. Tick Require the user to enter this password
  4. Enter a difficult to guess passphrase
  5. Close

Create Remote Desktop Client profile on your Client Machine

Do the following on the client machine:

remmina
  • remmina also in Dash under Remmina Remote Desktop Client

Ctrl+N or Connection > New

enter image description here

  1. Fill in your IP address [123.123.12.3] where it says Server
  2. Switch to the SSH tab

enter image description here

  1. Tick Enable SSH Tunnel
  2. Point your Desktop Client to your non-standard SSH port
  3. Set your SSH Authentication <username> and mode
  4. Connect

View and Control Host Machine

On the client machine, when asked for <username>'s password, enter it to create the SSH tunnel. When asked for the VNC password, enter the passphrase you previously entered into the host machine.

If successful at this step, you should now be viewing and controlling the host machine's desktop from your client machine through an SSH tunnel.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.