Ssh Setup

I have a Mac so these are the instructions for that. These instructions enable you to access your raspberry pi from another computer connected to the same network. I am following the remote access instructions here:

  • Find the IP Address
    • Make sure it’s powered on and connected to Wifi
    • Run ping raspberrypi.local (on host)
    • Note the IP Address
  • Enable SSH on Raspberry Pi
    • Go to Preferences > Raspberry Pi Configuration > Interfaces > SSH (Enable)
    • On host: ssh username@192.xxx.xxx.xxx <– IP Address noted from earlier
    • When asked about authenticity of host enter yes
    • After ssh’ing on host: touch ~/Desktop/foo.txt
    • You’ll see a txt file pop up on the Raspberry Pi Desktop!
  • Set up ssh-rsa key from host
    • Run ssh-keygen
    • ssh-copy-id username@192.xxx.xxx.xxx
    • Add to Apple Key Chain: ssh-add --apple-use-keychain ~/.ssh/id_rsa
    • Add the following to ~/.ssh/config (This enables persistence after reboot on Mac):
      Host *
        UseKeychain yes
        AddKeysToAgent yes
        IdentityFile ~/.ssh/id_rsa
      
  • Additional Steps to Secure Raspberry Pi
    • Disable SSH Password Login to Pi (on Pi): image
    • Require sudo to require password (on Pi): image
  • Prevent Wi-Fi is currently blocked by rfkill. message (You can do this via the UI)
  • Set other locale and configuration options (from Desktop on Pi, Preferences > Raspberry Pi Configuration)
  • iterm2 Quick SSH Profile image
  • Lastly I enabled auto-login under the Raspberry Pi preferences so that if it ever rebooted it wouldn’t hang at the login
  • Also, get Xquartz and make sure the GUI forwarding works (e.g. geany & (on Pi via SSH))
  • Turn off display using vcgencmd display_power 0, on is vcgencmd display_power 1 or after reboot it turns back on. This no longer works.
  • One thing I notice is that if the ethernet cable is unplugged from my raspberry pi, but it’s still connected over the wireless the private IP address changes. I can still login via ssh (using new IP address):

    ssh -A -Y yourusername@192.xxx.xxx.yyy

  • -A will allow you to forward the ssh agent which is super useful if you are going to be git pulling/pushing repositories

  • Set-up Permanent IP Address
    • I’m following the instructions here
    • First run netstat -nr
    • sudo nano /etc/dhcpcd.conf add the following (where xx.z is under Gateway of netstat):
      # Raspberry Pi Setup
      interface eth0
      metric 300
      static ip_address=192.168.xx.yyy/24
      static routers=192.168.xx.z
      static domain_name_servers=192.168.xx.z
      
      # Prioritize Ethernet Connection Over Wifi
      interface wlan0
      metric 200
      
  • sudo reboot
  • Easy ssh (ssh pi)
    • nano ~/.ssh/config add the following (on host Mac):
      Host pi
        Hostname 192.168.xx.yyy
        User your_username
        Port 22
        ForwardX11 yes
        ForwardX11Trusted yes
      
  • So now you can get there either way (I also set up a iterm profile)

  • I also forgot my wifi network:
    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    # Delete network=....
    # Crtl + x, y