VNC: Difference between revisions

From DWAMconsult Wiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Linux]]
[[Category:Linux]]
* Remote access of GUI in Linux (system you are remotely accessing must have GUI installed ...)
== VNC remote desktop viewer ==
* Instructions for RHEL / CentOS 7.4 and newer
* Install required packages: <code>yum -y install tigervnc-server tigervnc</code>
* Be logged in as the user on the remote system then create a VNC password: <code>vncpasswd</code>
** Can have multiple VNC sessions for different users
* As root, created systemd unit file for the user (create a different one for each remote user, changing 1 (which is for the first remote user) to 2, 3, etc)
** <code>cp /lib/systemd/system/[email protected] /etc/systemd/system/vncserver@:1.service</code>
** Edit this file and replace <USER> with the user name
* Enable firewall: <code>firewall-cmd --permanent --zone=public --add-port 5901/tcp</code> and <code>firewall-cmd --reload</code>
* Enable and start the VNC service: <code>systemctl enable vncserver@:1.service</code> and <code>systemctl start vncserver@:1.service</code> remembering you need to do this for each vncserver unit file where you have multiple remote users
* From client connect to the server using <servername or IP>:1 for the first user, :2 for second user etc
* More details: https://access.redhat.com/solutions/966063


== Better instructions ==
=== Instructions for RHEL etc ===


<nowiki>apt install xfce4 xfce4-goodies
* .
(only for server without GUI)


=== Instructions for Ubuntu/Debian ===


* Install VNC server on the system that you want to access <code>yum -y install tigervnc-server tigervnc</code>
* If the server doesn't have a GUI install one e.g. <code>tasksel</code>
* Get list of available desktop sessions: <code>ls /usr/share/xessions</code>
* As the user you'll be logging in as (not root), edit the config:


sudo apt install tightvncserver
<nowiki>vim ~/.vnc/config
sudo apt install dbus-x11
  session=gnome-xorg # obtained from the list of available sessions
vncserver
  geometry=1920x1080
set password
  localhost
set read-only password (useful for sharing session)
  alwaysshared</nowiki>
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
vim ~/.vnc/xstartup


#!/bin/bash
* As the user (not root), start vnc and configure a password and optional read-only password <code>vncserver</code>
xrdb $HOME/.Xresources
* Then kill the running vncserver process <code>vncserver -kill session:1</code>
startxfce4 &
* As root: <code>vim /etc/tigervnc/vncserver.users</code> and add the user e.g. <code>:1=david</code>
* Start and enable tigvervnc service


(for XFCE4. for gnome, startx?  what about ... Wayland?)
  <nowiki>systemctl start tigervncserver@:1.service
systemctl enable tigervncserver@:1.service</nowiki>


sudo chmod +x ~/.vnc/xstartup
* If necessary open the port in firewall on remote machine (likely 5901)
vncserver


connect securely like this:
== Configure tunnelling ==
ssh -L 5901:127.0.0.1:5901 -C -N -l david@your_server_ip


* On the machine using to access VNC running on server, do:
<nowiki>ssh -L 5901:127.0.0.1:5901 -N -f -l <username> <IP or FQDN of remote VNC server></nowiki>


once the secure tunnel is set up use vnc client to connect to localhost:5901
* Enter the password
 
* Now connect to localhost:5901 (or 127.0.0.1:5901) using e.g. Remmina
vim /etc/systemd/system/vncserver@.service
* Note: does not work if you're already logged in on the remote machine as that user. If you need to log in interactively, ssh to the remote server and stop the tigervnc service <code>systemctl stop tigervncserver@:1.service</code>
 
[Unit]
Description=Start TightVNC server at startup
After=syslog.target network.target
 
[Service]
Type=forking
User=sammy
Group=sammy
WorkingDirectory=/home/sammy
 
PIDFile=/home/sammy/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i
ExecStop=/usr/bin/vncserver -kill :%i
 
[Install]
WantedBy=multi-user.target
 
sudo systemctl daemon-reload
sudo systemctl enable vncserver@1.service
vncserver -kill :1
sudo systemctl start vncserver@1
sudo systemctl status vncserver@1
 
ssh -L 5901:127.0.0.1:5901 -C -N -l sammy your_server_ip
 
 
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-debian-11</nowiki>

Latest revision as of 01:08, 29 April 2024

VNC remote desktop viewer

Instructions for RHEL etc

  • .

Instructions for Ubuntu/Debian

  • Install VNC server on the system that you want to access yum -y install tigervnc-server tigervnc
  • If the server doesn't have a GUI install one e.g. tasksel
  • Get list of available desktop sessions: ls /usr/share/xessions
  • As the user you'll be logging in as (not root), edit the config:
vim ~/.vnc/config
  session=gnome-xorg # obtained from the list of available sessions
  geometry=1920x1080
  localhost
  alwaysshared
  • As the user (not root), start vnc and configure a password and optional read-only password vncserver
  • Then kill the running vncserver process vncserver -kill session:1
  • As root: vim /etc/tigervnc/vncserver.users and add the user e.g. :1=david
  • Start and enable tigvervnc service
systemctl start tigervncserver@:1.service
systemctl enable tigervncserver@:1.service
  • If necessary open the port in firewall on remote machine (likely 5901)

Configure tunnelling

  • On the machine using to access VNC running on server, do:
ssh -L 5901:127.0.0.1:5901 -N -f -l <username> <IP or FQDN of remote VNC server>
  • Enter the password
  • Now connect to localhost:5901 (or 127.0.0.1:5901) using e.g. Remmina
  • Note: does not work if you're already logged in on the remote machine as that user. If you need to log in interactively, ssh to the remote server and stop the tigervnc service systemctl stop tigervncserver@:1.service