I wanted to be able to remotely connect to my Raspberry Pi from my Windows machine, but how do you do that?
This was somewhat time-consuming to find and get working, so I wanted to write it down. First, I ended up doing everything from this page:
In case that page goes stale, here are the steps:
- Run this to install: sudo apt-get install tightvncserver
- Run once to configure password: /usr/bin/tightvncserver
To make it so it the VNC server starts every time, either run “sudo nano /etc/init.d/tightvncserver“ and put in the following:
#!/bin/sh
### BEGIN INIT INFO
# Provides: tightvncserver
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop tightvncserver
### END INIT INFO
# More details see:
# http://www.penguintutor.com/linux/tightvnc
### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER=’pi’
### End customization required
eval cd ~$USER
case “$1” in
start)
su $USER -c ‘/usr/bin/tightvncserver :1’
echo “Starting TightVNC server for $USER “
;;
stop)
pkill Xtightvnc
echo “Tightvncserver stopped”
;;
*)
echo “Usage: /etc/init.d/tightvncserver {start|stop}”
exit 1
;;
esac
exit 0
Or, if it’s available, you can pull it down from his server, move the file into place, change the owner, set the permission and then add it to the startup with something like this:
wget http://www.penguintutor.com/otherfiles/tightvncserver-init.txt
sudo mv tightvncserver-init.txt /etc/init.d/tightvncserver
sudo chown root:root /etc/init.d/tightvncserver
sudo chmod 755 /etc/init.d/tightvncserver
sudo update-rc.d tightvncserver defaults
sudo /etc/init.d/tightvncserver start
Reboot. Then, once you’re back up, connect to the machine with the VNC client, not just with the hostname, but with hostname:session (which is almost always going to be “1”). So, something like this:
One last thing, you might notice that Windows machines almost always get the same IP address from DHCP every time they boot up. Linux machines however almost always get a different address. So, it would be ideal to give your device a static IP address. Once you have that, you can modify your local DNS (if equipped) or your HOSTS file so that you can use a friendly name.
How do you make a Raspberry Pi use a static IP address instead of DHCP? It’s Linux, so it’s going to be a config file, silly! Again, here is the exact, full answer:
http://www.raspberryshake.com/raspberry-pistatic-ip-address/
However, because I don’t trust the internet and in case that page goes away, here is a summary of what to do. Edit the network config file by running “sudo nano /etc/network/interfaces”
Now, I have a wireless connection, so instead of modifying “eth0”, I should probably modify “wlan0” – however, I noted that there is that additional config file and plus wlan0 is set to “manual”.
So, on a whim, I tried modifying the “iface default inet dhcp” and changed it to “iface default inet static”. Then, immediately after it, you enter the details of your static IP address and network information, like this:
Save the file and reboot. Now, you can consistently connect VNC to “192.168.1.131:1” or if you configure DNS/change your HOSTS file, you can add a friendly name too.
So, Future Robert, that is how you get VNC running on Linux (and a Pi) – and how you configure one of these machines to have a static IP address instead of using DHCP.
Leave a Reply