Linux/VNC

From Omnia
Jump to navigation Jump to search

vnc

Virtual Network Computing

vncserver

vncserver uses realvnc or tightvnc

Simple Setup

Simple setup:

$ service vncserver start
$ vncpasswd
$ vncserver

To set password to empty: (need to have at least started vncserver once to get configs in place)

echo "" | vncpasswd -f > ~/.vnc/passwd

Installation

yum install vncserver xterm twm
# centos 7:
yum install tigervnc-server xterm
apt install tightvncserver

To hide vnc settings window

Change: (~/.vnc/xstartup)

#vncconfig -iconic &
vncconfig -nowin -iconic &

Also comment out the "xterm -geometry..." line so terminal doesn't start automatically.

Desktop Mangager

KDE

To start KDE automatically:

$ vi ~/.vnc/xstartup
  # replace "twm &" with...
  startkde &

Sample KDE xstartup file

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -nowin -iconic &
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
startkde &

GNOME

To start GNOME automatically:

$ vi ~/.vnc/xstartup
  # replace "twm &" with...
  exec gnome-session &

xfce4

yum install xfce4-session xfce-utils
apt-get install vnc4server xfce4
# CentOS 7:
yum install epel-release -y
#yum groupinstall "Xfce"
yum install xfce4-session

~/.vnc/xstartup:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
#vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
vncconfig -nowin -iconic &
xfconf-query -c xfce4-keyboard-shortcuts -p /xfwm4/custom/'<'Super'>'Tab -r
#xfce4-session &
startxfce4 &
xterm &

Ubuntu: (auto configured after installing xfce)

#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession

---

Fix tab completion not working: [1]

  • Clearing this key from xfce4-settings-manager => window manager => keyboard fixes the problem, OR...
    • Application Menu > Settings > Window Manager > Keyboard > clear "Switch window for same application"
  • xfconf-query -c xfce4-keyboard-shortcuts -p /xfwm4/custom/'<'Super'>'Tab -r

https://www.starnet.com/xwin32kb/tab-key-not-working-when-using-xfce-desktop/

https://bugzilla.xfce.org/show_bug.cgi?id=10760

See Xfce bug 10760

To fix this,

  • Open the Xfce Application Menu > Settings > Window Manager
  • Click on the Keyboard Tab
  • Clear the Switch window for same application setting

-

https://www.smork.info/blog/2015/06/10/fixing_bash_tab_completion_in_xfce.html

Edit the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

Find this line:

<property name="<Super>Tab" type="string" value="switch_window_key"/>

Change it to this:

<property name="<Super>Tab" type="empty"/>

Restart the VNC server:

vncserver -kill :1
vncserver

-

https://stackoverflow.com/questions/23418831/command-line-auto-complete-tab-key-not-work-in-terminal-for-ubuntu

Disable the behaviour of tab changing windows. This is done in the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml by changing the line

<property name="<Super>Tab" type="string" value="switch_window_key"/>

to

<property name="<Super>Tab" type="empty"/>

Reboot or restart your VNC server (XFCE).

twm

Tab Window Manager

twm - mouse

yum install vncserver xterm twm
apt-get install xterm twm

~/.vnc/xstartup:

...
twm &
xterm &

If you get errors with fonts:

LANG=C twm

Kill VNC Server

To kill a VNC server:

# where xxx is the display number (ie. :1)
vncserver -kill :xxx

SSH tunnel

SSH multiple tunnel:

For example the the first tunnel would be:
 
ssh -L 5901:localhost:4321 <user>@<gateway.machine>
 
and then on the gateway machine
 
ssh -L 4321:localhost:5901 <user>@<server.machine>

After setting up the tunnels, you can start the VNC client as usual
 
vncviewer -shared localhost:1 

Autostart VNC for Select User

If you want to access your server via VNCServer, you can automatically start the VNCServer at startup. You have to select a user under which the server will be running. Then, edit

/etc/sysconfig/vncservers

and add your users line on the bottom:

VNCSERVERS="1:Username"

Using usernames to login

Simplifying Remote VNC Logins

You will need to configure GDM to accept remote login requests.

DISPLAY

export DISPLAY=:0
xterm &

References

Virtual Network Computing

TightVNC

TightVNC: VNC-Compatible Free Remote Control / Remote Desktop Software - TightVNC: VNC-Compatible Free Remote Control / Remote Desktop Software

apt-get install tightvncserver

Set Resolution

vncserver -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768

Then resize with:

xrandr -s 1600x1200
xrandr -s 1440x900
xrandr -s 1024x768

---

Error:

RandR extension missing

Install xrandr dependency:

sudo apt-get install libxrandr-dev x11-xserver-utils

---

If you need to change the setting without restarting VNC server, I had good results with:

vncconfig -set RandR="1024x768,1600x900"

and then using xrandr to change resolution as fgregg suggested:

xrandr -s 1024x768
xrandr -s 1600x900

---

Ref: [2]

Resize VNC Session

Great for headless:

vnc_resize.sh:

#!/bin/bash

if [ "$1" == "" -o "$2" == "" ] ; then
  echo "Usage: [width] [height]"
  exit 1
fi

DISP=`xrandr --prop | grep connected`
if [ $? -ne 0 ] ; then
  echo "Run this from graphics session"
  exit 1
fi

MODELINE=`cvt $1 $2 | tail -n 1 | sed 's/Modeline //'`
MODE=`echo $MODELINE | awk '{print $1}'`
DISP=`echo $DISP | awk '{print $1}'`

echo $MODELINE
echo $MODE
echo $DISP

xrandr --newmode $MODELINE
xrandr --addmode $DISP $MODE
xrandr --fb $1x$2

1. Calculate the Modeline:

$ cvt 1440 900
Modeline "1440x900_60.00"  106.50  1440 1528 1672 1904  900 903 909 934 -hsync +vsyn

2. Create mode:

$ xrandr --newmode "1440x900_60.00" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync

3. Find Display:

xrandr --prop
   VGA-0 ...

4. Add Mode:

$ xrandr --addmode VGA-0 "1440x900_60.00"

5. Set Mode:

xrandr --fb 1440x900

Remote Desktop Sharing

Vino

sudo apt-get install vino dconf-editor

# as pi user...
gsettings set org.gnome.Vino require-encryption false
gsettings set org.gnome.Vino prompt-enabled false
gsettings set org.gnome.Vino authentication-methods "['none']"


## sudo su -
## cat > /etc/sudoers.d/vsrv.sh << "EOF"
## #!/bin/bash
## /usr/lib/vino/vino-server
## EOF
## chmod +x /etc/sudoers.d/vsrv.sh
## 
## cat >> /etc/xdg/lxsession/LXDE/autostart << "EOF"
## @/etc/sudoers.d/vsrv.sh
## EOF

sudo su -
cat > /etc/xdg/autostart/vino-server.desktop << "EOF"
[Desktop Entry]
Name=Desktop Sharing
Comment=GNOME Desktop Sharing Server
Exec=/usr/lib/vino/vino-server
Terminal=false
Type=Application
X-GNOME-Autostart-Phase=Applications
X-GNOME-AutoRestart=true
NoDisplay=true
EOF

RPi VNC Screen Sharing - eLinux.org - http://elinux.org/RPi_VNC_Screen_Sharing

Screen Capture

vncdo

sibson/vncdotool · GitHub - https://github.com/sibson/vncdotool

"vncdotool is a command line VNC client. It can be useful to automating interactions with virtual machines or hardware devices that are otherwise difficult to control."

Screen capture:

vncdo -s myserver:0 -p mypassword capture 1.png capture 2.png

--

Install:

pip install vncdotool

--

Usage:

vncdo -s vncserveraddress type "hello world"
vncdo -s vncservername capture screen.png

--

More examples of usage:

Putting it all together you can specify multiple actions on a single command line. You could automate a login with the following:

> vncdo type username key enter expect password_prompt.png
> vncdo type password move 100 150 click 1 expect welcome_screen.png

--

pypi - vncdotool 0.2.0 : Python Package Index - https://pypi.python.org/pypi/vncdotool/0.2.0

vncsnapshot

VNC Snapshot - http://vncsnapshot.sourceforge.net/

"VNC Snapshot is a command line utility for VNC (Virtual Network Computing) available from RealVNC, among others. The utility allows one to take a snapshot from a VNC server and save it as a JPEG file. Unix, Linux and Windows platforms are supported."

Example:

vncsnapshot some_server:1 -passwd vnc_passwd_file screenshot.jpg

Note: Read encrypted password from filename instead of from the console. The filename can be made with the vncpasswd utility included in the vncsnapshot distribution.