VNC: Difference between revisions

From DWAMconsult Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:


* Install VNC server on the system that you want to access <code>yum -y install tigervnc-server tigervnc</code>
* 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>
* Be logged in as the user on the remote system then create a VNC password: <code>vncpasswd</code>
* Get list of available desktop sessions: <code>ls /usr/share/xessions</code>
** Can have multiple VNC sessions for different users
* As the user you'll be logging in as (not root), edit the config:
* 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 ==
<nowiki>vim ~/.vnc/config
  session=gnome-xorg # obtained from the list of available sessions
  geometry=1920x1080
  localhost
  alwaysshared</nowiki>


<nowiki>apt install xfce4 xfce4-goodies
* As the user (not root), start vnc and configure a password and optional read-only password <code>vncserver</code>
(only for server without GUI)
* Then kill the running vncserver process <code>vncserver -kill session:1</code>
* As root: <code>vim /etc/tigervnc/vncserver.users</code> and add the user e.g. <code>:1=david</code>
* Start and enable tigvervnc service


<nowiki>systemctl start tigervncserver@:1.service
systemctl enable tigervncserver@:1.service</code>


* If necessary open the port in firewall (likely 5901)


sudo apt install tightvncserver
== Configure tunnelling ==
sudo apt install dbus-x11
vncserver
set password
set read-only password (useful for sharing session)
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
vim ~/.vnc/xstartup


#!/bin/bash
* On the machine using to access VNC running on server, do:
xrdb $HOME/.Xresources
startxfce4 &
<nowiki>ssh -L 5901:127.0.0.1:5901 -N -f -l <username> <IP or FQDN of remote VNC server></nowiki>


(for XFCE4.  for gnome, startx?  what about ... Wayland?)
* Enter the password
 
* Now connect to localhost:5901 using e.g. Remmina
sudo chmod +x ~/.vnc/xstartup
* 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>
vncserver
 
connect securely like this:
ssh -L 5901:127.0.0.1:5901 -C -N -l david@your_server_ip
 
 
once the secure tunnel is set up use vnc client to connect to localhost:5901
 
vim /etc/systemd/system/[email protected]
 
[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>

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</code>

* If necessary open the port in firewall (likely 5901)

== Configure tunnelling ==

* 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>
  • Enter the password
  • Now connect to localhost: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