EL7 Remote Access Made Easy
Remote access of a RHEL machine is very simple and can be done in a variety of ways. There are two that go hand-in-hand that I have been deploying for ages : sshd and x2go (formerly nx). As x2go uses ssh to make connections we will cover that second. Thirdly, we have x11vnc. And as a fourth viable option, we have rdp. As I find rdp a bit on the dangerous side security-wise, I will include it, but advise against and to stick with ssh/x2go as its a better model, and cross platform if you do not need session sharing, if you do, x11vnc.
SETTING UP SSHD
Setting this up is easy, but critically important that its done sanely, intelligently, and correctly. There are a few options that are a must and a few that are optional. I will presume your ability to read, and allow you to do that on your own to develop your own file, but will go over a few options that really do need to be set, and a few that if you plan accordingly can be a valuable asset.
Install sshd if need be:
$ yum info openssh-server Loaded plugins: langpacks, nvidia, product-id, subscription-manager Installed Packages Name : openssh-server Arch : x86_64 Version : 6.6.1p1 Release : 12.el7_1 Size : 916 k Repo : installed From repo : rhel-7-desktop-rpms Summary : An open source SSH server daemon URL : http://www.openssh.com/portable.html License : BSD Description : OpenSSH is a free version of SSH (Secure SHell), a program for : logging into and executing commands on a remote machine. This : package contains the secure shell daemon (sshd). The sshd daemon : allows SSH clients to securely connect to your SSH server.
First disable root logins. This is ALWAYS a good idea to put into place as it is NEVER a good idea for machines to allow remote root logins. Use sudo or su to gain root privileges. Find the line that includes the parameter and fix it to be this:
If you are not Chuck Norris of security (selinux included), its a very sane idea to change your sshd port somehow. For simplicity, if you want one place to fix many machines behind a NATted connection, fix it there -- the NAT machine. Have it accept on different ports than 22 and forward to the LAN on 22. But if this is a single or one of a small handful of machines, you can remap the port. Here is the parameter in question:
Disable the ancient Protocol 1 by forcing Protocol 2 only.
Spawn new processes with the exactly needed privileges
Be anal about client config options that are passed to your server
This is to enforce that a rarely needed utility isn't put into place by accident. If you need this you will know, but if you don't need this, this sounds like gibberish.
We want real passwords!
Notify on login when last login was
Forward X11 display connections. This is a needed option for using x2go
PASSWORDLESS SSH LOGINS
To not use a password, but rather ssl keys, its a simple and much more secure approach.
Generate SSL keys if need be. Root will need to do this for sshd only. Each respective user will need to run this to create their own keys.
client : ssh-keygen server : sudo ssh-keygen
For each system that you wish to do this on issue the following command
For example (with error for obvious reason):
$ ssh-copy-id schotty.com /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
SETTING UP X2GO
x2go is a great resource for getting a remote X11/Xorg session easily. Here are the steps needed for this to work.
$ sudo yum info x2goserver-xsession Loaded plugins: langpacks, nvidia, product-id, subscription-manager Available Packages Name : x2goserver-xsession Arch : x86_64 Version : 220.127.116.11 Release : 3.el7 Size : 13 k Repo : epel/x86_64 Summary : X2Go Server Xsession runner URL : http://www.x2go.org License : GPLv2+ Description : X2Go is a server based computing environment with : - session resuming : - low bandwidth support : - session brokerage support : - client side mass storage mounting support : - audio support : - authentication by smartcard and USB stick : : This X2Go server add-on enables Xsession script handling : when starting desktop sessions with X2Go. : : Amongst others the parsing of Xsession scripts will : enable desktop-profiles, ssh-agent startups, gpgagent : startups and many more Xsession related features on : X2Go session login automagically.
Since certain desktop environments do things that x2go doesn't support (on the server side only), install a compatible DE for use with the remote sessions. This does not impact local users to that system, as you can use an unsupported DE locally, and another remotely. http://wiki.x2go.org/doku.php/doc:de-compat Here are the recommended DE group install commands:
sudo yum groupinstall "Xfce" sudo yum groupinstall "MATE Desktop"
Firewalld will need some fixing:
sudo firewall-cmd --permanent --zone=public --add-service=ssh sudo firewall-cmd --zone=public --add-service=ssh sudo firewall-cmd --reload
Client side you will need to find an appropriate x2go client. On my RHEL7 systems I went this route:
$ sudo yum info x2goclient Loaded plugins: langpacks, nvidia, product-id, subscription-manager Installed Packages Name : x2goclient Arch : x86_64 Version : 18.104.22.168 Release : 1.el7 Size : 2.5 M Repo : installed From repo : epel-testing Summary : X2Go Client application (Qt4) URL : http://www.x2go.org License : GPLv2+_ _Description : X2Go is a server based computing environment with : - session resuming : - low bandwidth support_ _: - session brokerage support : - client-side mass storage mounting support : - client-side printing support : - audio support : - authentication by smartcard and USB stick : : X2Go Client is a graphical client (Qt4) for the X2Go system. : You can use it to connect to running sessions and start new : sessions.
Configuration is rather straight forward, but there are a few things to take note of. Firstly the main issue that can be easily avoided is using the wrong sessions. Check towards the bottom of the new session editor for what session is selected (if any), and pick the appropriate one. This is vital if you are using an unsupported DE as there are parameters that will need to go with it. And in case it needs to be said, tick the box for using keys rather than passwords if you prefer the ssl key route over password auth. That's it! Sometimes after crash scenarios, X2Go will not accept new connections and complain about authentication issues. This is misleading as %99 of the time this is actually the session database corrupted. To fix, do the following two instructions:
sudo rm /var/lib/x2go/x2go_sessions sudo x2godbadmin --createdb
On th occasion that one's Windows client has issues with the known_hosts file, the file can be fixed/deleted here:
SETTING UP X11VNC
x11vnc is a x11/xorg screen sharing capable vnc server. Via this, you may have a logged in as a user, you can share your active session. Here are the steps to sanely setup this on your system.
Package Info on RHEL7 as of time of writing
Name : x11vnc Arch : x86_64 Version : 0.9.13 Release : 11.el7 Size : 857 k Repo : epel/x86_64 Summary : VNC server for the current X11 session URL : http://www.karlrunge.com/x11vnc/ License : GPLv2 Description : What WinVNC is to Windows x11vnc is to X Window System, i.e. a : server which serves the current X Window System desktop via RFB : (VNC) protocol to the user. : : Based on the ideas of x0rfbserver and on LibVNCServer it has : evolved into a versatile and productive while still easy to use : program.
sudo yum install x11vnc
Set user's password
Invoke server as user
x11vnc -usepw -ncache -forever -display :1 -ultrafilexfer -auth guess
Ensure that you ONLY have ssh access to the system. DO NOT open up any VNC ports
- On remote system install a VNC viewer application
- Invoke vncviewer
vncviewer -via YOUR-VNCSERVER localhost:0
With this setup you have
* An ssh tunnel * A password to protect the screen * Remote access to your active Xorg session
SETTING UP XRDP
Install the Nux! repo and EPEL (if not already present).
- EPEL is a prerequisite for Nux's functionality http://li.nux.ro/repos.html
Install vnc and xrdp
sudo yum install tigervnc-server xrdp
Open up the firewall
sudo firewall-cmd --permanent --zone=public --add-port=3389/tcp sudo firewall-cmd --reload
sudo systemctl enable xrdp sudo systemctl start xrdp
On the client, you can use your favorite rdp tool to connect up. On RHEL6/7 I prefer to use Remmina :
$ yum info remmina Loaded plugins: langpacks, nvidia, product-id, subscription-manager Installed Packages Name : remmina Arch : x86_64 Version : 1.0.0 Release : 8.el7.nux Size : 897 k Repo : installed From repo : nux-dextop Summary : Remote Desktop Client URL : http://remmina.sourceforge.net License : GPLv2+ and MIT Description : Remmina is a remote desktop client written in GTK+, aiming to be : useful for system administrators and travelers, who need to work : with lots of remote computers in front of either large monitors or : tiny netbooks. : : Remmina supports multiple network protocols in an integrated and : consistent user interface. Currently RDP, VNC, XDMCP and SSH are : supported. : : Please don't forget to install the plugins for the protocols you : want to use.
sudo yum install remmina remmina-plugins-*
SETTING UP X11 FORWARDING
X11 Forwarding will allow for running a remote application on your local display.
Setup X11 Forwarding on remote system
# sudo vim /etc/ssh/sshd_conf * fix the following three lines, although the offset may not be needed X11Forwarding yes X11DisplayOffset 10 X11UseLocalhost yes
sudo systemctl restart sshd
On local system, fix ssh to allow for X11 Forwarding:
sudo vim /etc/ssh/ssh_config * Fix the following two lines Host * ForwardX11 yes
On local machine execute ssh in the following way:
# ssh -X host # ssh -X user@host
Now if remoted in to your system, and "gedit" is executed, it will display locally.
Now depending on issues that may crop up with the permissions system, you may require fixing your root user's .Xauthority file if you need to run remote applications as root. To allow for a user to run an application as root, do the following:
sudo su xauth merge /home/user/.Xauthority