SSHing into your Raspberry Pi
Secure Shell (SSH) is a way to remotely access your Pi from any computer connected to the same network as your Pi; this means you can have it running in your room while accessing it with your laptop elsewhere on campus. Unfortunately, WashU’s network system makes this more complicated than normal, so we need to set up SMTP on your Pi in order to email its IP address to you.
For the initial set up of the pi, follow this guide here. You will need a monitor, mouse, and keyboard for the rest of this tutorial but afterwards they will not be needed once you’re connected on another device. These items can be found in Urbauer 015-- Please use only the monitors not connected to a computer, and return everything you use to its original place after finishing. If your Pi is not a 3 or zero, you will also need an Ethernet cable.
- On the device you want to use to access your Pi, download and install the SSH client PuTTY: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
- Boot up your Pi. If this is the first time, you may be presented with the raspi-config menu; otherwise open the command prompt and type “sudo raspi-config” to access it. Enable SSH and then exit with “finish.”
- On your Pi, connect to wustl-guest-2.0 on the top right corner of your screen. Then hover over the network icon to find the Pi’s public IP address.
- Open PuTTY. Where it says host name, type the IP address, omitting the “/” and everything afterwards. Make sure your device is connected to the same network. For port number use 22 and for connection type select the SSH option. Click “open.”
- A command terminal will pop up. It may take a while for any text to show up. When prompted, type “pi” as your login and “raspberry” as your password, and then you should have access to the Pi’s terminal! It will then advise you to change your password, which is advisable to do as soon as possible for security reasons.
- When ready, type “sudo halt” to shut down or “sudo reboot” to restart. Always halt before pulling the plug.
Emailing the IP address
Upon future reboots the Pi may use different addresses, preventing you from SSHing into it when you don’t have access to a monitor to check it. Now we will configure the Pi to email its address to you every time it starts up.
- Install ssmtp by typing “apt-get update && apt-get install ssmpt” in the command prompt
- If you get an access denied error, append “sudo “ to the front of the above statement.
- Type “sudo nano /etc/ssmtp/ssmtp.conf”. In the document that appears, change/add the following lines:
AuthUserfirstname.lastname@example.org AuthPass=ese205rulz FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES
- Save and exit by hitting ctrl+X, then y, then enter.
- Ensure Sendmail is turned off by using the following lines in the command prompt:
$ service sendmail stop $ chkconfig sendmail off $ mkdir /root/.bakup $ mv /usr/sbin/sendmail /root/.bakup $ ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail
- You should be able to send emails from your Pi now from the address email@example.com. To test this, type “echo "This is a test" | mail -s "Test" firstname.lastname@example.org” and check your inbox.
- Type “sudo nano /etc/ip_emailer.sh” to create a new script. In the new file, write the lines
#!/bin/bash ifconfig -a | mail -s "RasPi IP" email@example.com
- Save and exit with ctrl+X.
- Make the script executable with “chmod 774 /etc/ssmtp/ssmtp.conf”.
- To schedule this script to be run upon reboot, type “sudo crontab –e”.
- At the bottom of the script, add the line “@reboot /etc/ip_emailer.sh”. Save and exit.
- Reboot the Pi. You should receive an email containing its IP address you can now use to SSH into your Pi from anywhere on campus! If you do not receive an email, the Pi may be having trouble connecting to the network; try moving it to a different location or trying again later.
Beyond the Command Prompt
If you wish to access the full Pi desktop and not just the command prompt from your laptop, follow this guide to set up a VNC server: https://classes.engineering.wustl.edu/ese205/core/index.php?title=Autostarting_Raspberry_Pi_Using_VNC_Viewer