Ubuntu – How login a user on desktop screen using ssh

14.04ssh

I wanted to be able to login users on their desktop using ssh. I've a lot of clients and I want to log all of them in using ssh from the server. I'm using Ubuntu 14.04. How can this be accomplished?

Edit: in order to clarify a bit more:
Let's say I'm in computer A. I use an ssh connection to computer B. I want to login computer B in such a way that a person sitting behind computer B see the computer logged in as if he himself logged in manually.
I mean, I want to do something so that it'll be exactly as if a user sat behind computer B, entered the password and logged in.

Best Answer

After hours of searching in Google and trying different things I ended up with two ways to do this:

  1. First make your user auto-login by creating file /etc/lightdm/lightdm.conf with this content:

    [SeatDefaults]
    autologin-user=YOUR_USERNAME
    autologin-user-timeout=0
    user-session=ubuntu
    greeter-session=unity-greeter
    

    (for more information How do I enable auto-login in LightDM?)

    Then you must restart lightdm using the command:

    service lightdm restart
    

    This results in lightdm logging automatically using your username. Now you can remove the file /etc/lightdm/lightdm.conf in order to disable auto-login for your user again.

  2. You must first stop lightdm using the command:

    service lightdm stop
    

    then you must use the following command to start an x-session manually:

    su - YOUR_USERNAME "startx -- :0 vt7" &
    

    this command starts a new x-session logged in with your username on tty7, the default tty for lightdm. the & sign at the end detaches this process.

    Note 1: if you receive an error saying

    X: user not authorized to run the X server, aborting.

    you must edit the file located at /etc/X11/Xwrapper.config and set allowed_users to anybody. After the start of the x-session you can return it to the previous value(normally console) for security reasons.

    Note 2: If your x-session is showing only the desktop and not the unity panels, try removing files .config and .cache located at home folder of your user.

If you know any better ways or some improvement you might think is useful please share it here. Thank you.