Sieci komputerowe 1

How to use XRDP

  1. Install XRDP Package from Ubuntu Repository. Do this either with command
    sudo apt-get install xrdp
    
    or with Synaptic or any other package manager software/method.
  2. Install the xfce4 Desktop environment. I was succeed with this desktop environment and fail with others. You are free to test other options...
    sudo apt-get install xfce4
    
    To verify desktop environment installed on your system you can try
    fulmanp@ubuntu:~$ ls -l /usr/bin/*session
    -rwxr-xr-x 1 root root  10456 mar  4  2013 /usr/bin/ck-launch-session
    -rwxr-xr-x 1 root root 235904 mar 26  2015 /usr/bin/gnome-session
    -rwxr-xr-x 1 root root 221736 sty  7  2015 /usr/bin/lxsession
    -rwxr-xr-x 1 root root    594 gru 22  2013 /usr/bin/openbox-session
    -rwxr-xr-x 1 root root 182504 mar 21  2014 /usr/bin/xfce4-session
    
  3. Configure XRDP to use XFCE desktop environment
    echo xfce4-session >~/.xsession
    sudo service xrdp restart
    
  4. Test XRDP connection. To do this, find the ip address of the linux machine you are working on, for example with a command
    fulmanp@ubuntu:~$ hostname -I
    192.168.48.159
    
  5. Switch to a windows machine, start Remote Desktop Connection (Podłączanie pulpitu zdalnego) and enter the ip address/name of the linux machine
  6. You should see the login screen of XRDP presented to you
  7. Enter your username and password and confirm with pressing OK button. If everything is configured correctly, you should see a XFCE desktop loading
    and you should be able to work on remote machine.
  8. Notice that if connected to an XRDP session, logging out of the xfce4 desktop will not terminate the XRDP remote session, but rather it will leave your session in a state of limbo. We can verify this printing contents of
    /tmp/.X11-unix
    directory before login, during a session and after a logout
    fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
    razem 0
    srwxrwxrwx 1 root root 0 maj 16 11:26 X0
    fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
    razem 0
    srwxrwxrwx 1 root    root    0 maj 16 11:26 X0
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 14:57 X12
    fulmanp@ubuntu:/tmp/.X11-unix$ 
    
    As you can see, in this case, a directory X12 was created and wasn't removed after logout. Establishing new XRDP connections over the same port (see further) will not remedy this malfunction either, so in order to kill the connection without restarting Ubuntu, the following must be done:
    1. The user session must be deleted. Navigate to the /tmp/.X11-unix directory. Always there will be a root session running on X0. Remember do not kill this session. Our limbo session, should appear as something similar to X12. To kill the session, type the following
      sudo rm X12
      
    2. All processes running for that user must be killed. To view running processes for a user account, you can type for example
      top -U ‘username’
      
      or
      fulmanp@ubuntu:~$ ps -u fulmanp
      
      There are many ways you can kill them:
      • Use hard kill (SIGKILL)
        kill -9 processname
        
      • or do soft kill (SIGTERM)
        kill -15 processname
        
      • Alternatively to do this faster you can try pkill or killall
        • The pkill command works in almost exactly the same way as kill, but it operates on a process name instead
          pkill [processname]
          
          or username
          pkill -u [username]
          
        • If you would like to send a signal to every instance of a certain process, you can use the killall
          killall [processname] 
          
          or
          killall --user [username] 
          

XRDP from linux to linux

  1. Connecting with XRDF from linux to linux is very similar - compare following screens




Reconnect to the same session

As we mentioned earlier, every time we connect through XRDP we get a new session which is not what we want in most cases. First login
fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
razem 0
srwxrwxrwx 1 root    root    0 maj 16 20:50 X0
srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:29 X10

Disconnect from our running session and again login
fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
razem 0
srwxrwxrwx 1 root    root    0 maj 16 20:50 X0
srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:29 X10
srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:36 X11

To change this do the following.
  1. Edit xrdp.ini file located under the /etc/xrdp directory
    sudo gedit /etc/xrdp/xrdp.ini
    
  2. Locate the section [xrdp1] and replace the line
    port=-1
    
    with the line
    port=ask-1
    
  3. Restart the XRDP service
    sudo service xrdp restart.
    
  4. Start remote desktop client as previously. You will see that the XRDP login screen has an additional field called port.

  5. If this is your first connection, leave the default value in the port field (i.e. -1), you will be then connecting through XRDP to your remote machine using a specified port that can be seen on the login process dialog box. Important: remember this port number - you will need it while reconnecting.

  6. Again, new session has been started
    fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
    razem 0
    srwxrwxrwx 1 root    root    0 maj 16 20:50 X0
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:29 X10
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:36 X11
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:48 X12
    
    Open some applications

    and disconnect from our running session.
  7. Try to (re)connect. You will have to specify the same port as your first connection

    and you should see the same screen as you left it.

    fulmanp@ubuntu:/tmp/.X11-unix$ ls -l
    razem 0
    srwxrwxrwx 1 root    root    0 maj 16 20:50 X0
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:29 X10
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:36 X11
    srwxrwxrwx 1 fulmanp fulmanp 0 maj 16 21:48 X12