Skip to content

Instantly share code, notes, and snippets.

@jeremyfix
Last active December 2, 2020 12:43
Show Gist options
  • Save jeremyfix/57cd27a658505e37444054ccffc2e836 to your computer and use it in GitHub Desktop.
Save jeremyfix/57cd27a658505e37444054ccffc2e836 to your computer and use it in GitHub Desktop.
Configuring remote accounts for using vnc

For copying your ssh keys to facilitate the configuration

for i in {1..59}; do sshpass -p THE_SECRET_PASSWORD ssh-copy-id myacount_$i@mymachine.mydomain.com ; done

For setting up the xstartup script

  for i in {1..59}; do ssh myacount_$i@mymachine.mydomain.com << 'EOF'
  mkdir -p ~/.vnc/
  echo "#!/bin/sh" >> ~/.vnc/xstartup
  echo "# Start Xfce4 Desktop" >> ~/.vnc/xstartup
  echo "[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup" >> ~/.vnc/xstartup
  echo "[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources" >> ~/.vnc/xstartup
  echo "vncconfig -iconic &" >> ~/.vnc/xstartup
  echo "dbus-launch --exit-with-session xfce4-session &" >> ~/.vnc/xstartup
  EOF
  done

For adding a startup VNC script disabling password

Note: it is not a good idea to use SecurityTypes None except that in the case of the command below (localhost=no by default), you have to establish a connection to the localhost which I do in a secured way.

  for i in {1..59}; do ssh myacount_$i@mymachine.mydomain.com << 'EOF'
  mkdir -p ~/.local/bin
  echo "#!/bin/bash" >> ~/.local/bin/startvnc.sh
  echo "vncserver -SecurityTypes None -depth 32 -geometry 1680x1050" >> ~/.local/bin/startvnc.sh
  chmod u+x ~/.local/bin/startvnc.sh
  echo "export PATH=\$PATH:~/.local/bin" >> ~/.bashrc
  EOF
  done

For adding a stop VNC script

  for i in {1..59}; do ssh myacount_$i@mymachine.mydomain.com << 'EOF'
  echo "#!/bin/bash" >> ~/.local/bin/stopvnc.sh 
  echo "vncserver -kill" >> ~/.local/bin/stopvnc.sh
  chmod u+x ~/.local/bin/stopvnc.sh
  EOF
  done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment