Wednesday 31 March 2021

How to setup vncserver in

SERVER SIDE
===========
apt update
apt install xfce4 xfce4-goodies tightvncserver
apt install xfonts-base x11-xserver-utils

# Prompts to set up password for VNC server here...
vncserver

# Allow clients to connect to X server from any host
export DISPLAY=:1
xhost +
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

# Creating proper config and restarting the server
cat << EOF > ~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
EOF

# Creating a user account
chmod +x ~/.vnc/xstartup
export USERNAME="vncuser"
useradd --create-home $USERNAME
adduser $USERNAME sudo
passwd $USERNAME

# Copy ssh keys to new user
mkdir -p /home/$USERNAME/.ssh
cp ~/.ssh/authorized_keys /home/$USERNAME/.ssh/
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh

# Copy VNC settings to a new user
mkdir -p /home/$USERNAME/.vnc
cp ~/.vnc/xstartup /home/$USERNAME/.vnc/
chown -R $USERNAME:$USERNAME /home/$USERNAME/.vnc/
touch ~/.Xauthority Log


# Stop command. Just in case. Ignore errors here
su $USERNAME -c "vncserver -kill :1"

# Start VNC server
su $USERNAME -c "vncserver -depth 24 -geometry 1280x800"
su vncuser -c vncserver

CLIENT SIDE
===========
Download and install tightvnc viewer
https://www.tightvnc.com/download.php
Ensure vncserver is started in server side
Launch tightc vncviewer
specify ipaddress as server-ip-address:port 
(eample:143.198.113.69:5901)
Password will be accepted

VNC TERMINAL will be launched