Skip to content

Instantly share code, notes, and snippets.

@denistex
Last active November 6, 2021 09:51
Show Gist options
  • Save denistex/599573b3b0810d467e93bc917c737e3e to your computer and use it in GitHub Desktop.
Save denistex/599573b3b0810d467e93bc917c737e3e to your computer and use it in GitHub Desktop.
How to configure Debian with i3wm and VNC access in AWS cloud

Instance configuration

  1. Add PEM file in AWS (if you don't have one).
  2. Set PEM file permissions: chmod 600 PEMFILE.
  3. Create new Debian instance in AWS console.
  4. Update instance credentials in following scripts:
    • up-instance.sh
    • dn-instance.sh
    • ssh2aws.sh
    • scp2aws.sh
    • vncview.sh
  5. Log in with following command: ./ssh2aws.sh.
  6. Go root: sudo su -.
  7. Disable root password in /etc/shadow (change root:*:... to root:!:... ).
  8. Add admin user to group tty: usermod -a -G tty admin.
  9. Instal required software: ./install.sh.
  10. Go back to admin: C-d.
  11. Start VNC server and set passwords: vncserver.
  12. Stop server: ./stopvnc.sh.
  13. Move xstartup to VNC directory: mv xstartup ~/.vnc/.
  14. Disconnect from the instance: C-d.
  15. Connect to the instance with SSH tunnel: ./ssh2aws.sh 5901.

To start VNC server use ./startvnc.sh.

To stop VNC server use ./stopvnc.sh.

Local configuration

  1. Install VNC viewer.
  2. Connect: ./vncview,sh.

Useful links

  1. http://www.brianlinkletter.com/how-to-run-gui-applications-xfce-on-an-amazon-aws-cloud-server-instance/
#!/bin/bash
# Your instance ID
INSTANCE=i-396ac2a33748bb784
echo "Stopping instance..."
aws ec2 stop-instances --instance-ids $INSTANCE
echo "Waiting for instance stopped..."
aws ec2 wait instance-stopped --instance-ids $INSTANCE
echo "Done."
#!/bin/bash
apt-get update
apt-get install --no-install-recommends --assume-yes xorg xserver-xorg-legacy i3 i3status vnc4server tigervnc-common
#!/bin/bash
# Your instance ID
INSTANCE=i-396ac2a33748bb784
# Your PEM file
PEM=aws.pem
REMOTE_USER=admin
echo "Waiting for instance started..."
aws ec2 wait instance-running --instance-ids $INSTANCE
echo "Querying instance DNS name..."
HOST=$(aws ec2 describe-instances --instance-ids $INSTANCE --query 'Reservations[0].Instances[0].PublicDnsName' | tr -dc '[:alnum:]-.')
echo "Instance DNS name: \"$HOST\"."
if [ -f $PEM ]; then
echo "Starting SSH copy..."
scp -r -i $PEM $1 $REMOTE_USER@$HOST:$2
else
echo "SSH copy cancelled: PEM file ($PEM) not found."
fi
#!/bin/bash
# Your instance ID
INSTANCE=i-396ac2a33748bb784
# Your PEM file
PEM=aws.pem
PORT=$1
if [ $PORT ]; then
echo "Port forwarding enabled for ${PORT}."
FORWARD="-L $PORT:localhost:$PORT"
fi
echo "Waiting for instance started..."
aws ec2 wait instance-running --instance-ids $INSTANCE
echo "Querying instance DNS name..."
NAME=$(aws ec2 describe-instances --instance-ids $INSTANCE --query 'Reservations[0].Instances[0].PublicDnsName' | tr -dc '[:alnum:]-.')
echo "Instance DNS name: \"$NAME\"."
if [ -f $PEM ]; then
echo "Opening SSH session..."
ssh $FORWARD -i $PEM admin@$NAME
else
echo "SSH session cancelled: PEM file ($PEM) not found."
fi
#!/bin/bash
vncserver -geometry 1920x1080 -localhost yes
#!/bin/bash
vncserver -kill :1
#!/bin/bash
# Your instance ID
INSTANCE=i-396ac2a33748bb784
# Your PEM file
PEM=aws.pem
echo "Starting instance..."
aws ec2 start-instances --instance-ids $INSTANCE
echo "Waiting for instance started..."
aws ec2 wait instance-running --instance-ids $INSTANCE
echo "Querying instance DNS name..."
NAME=$(aws ec2 describe-instances --instance-ids $INSTANCE --query 'Reservations[0].Instances[0].PublicDnsName' | tr -dc '[:alnum:]-.')
echo "Instance DNS name: \"$NAME\"."
if [ -f $PEM ]; then
echo "Opening SSH session..."
ssh -L 5901:localhost:5901 -i $PEM admin@$NAME
else
echo "SSH session cancelled: PEM file ($PEM) not found."
fi
#!/bin/bash
vncviewer -FullColor -passwd vnc-password localhost:1
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startx &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
x-window-manager &
x-terminal-emulator &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment