Difference between revisions of "Raspberry Pi SSH Without Logging In"

From TheBeard Science Project Wiki
Jump to: navigation, search
(Created page with "I'm very annoyed that I can't just throw a Raspbian image onto an SD card and SSH into it without pulling out an HDMI monitor and keyboard. I finally have all the steps necess...")
 
Line 11: Line 11:
  
 
(Optional WiFi) Create a file in the boot partition called "wpa_supplicant.conf" and enter this content:
 
(Optional WiFi) Create a file in the boot partition called "wpa_supplicant.conf" and enter this content:
 +
<source>
 +
country=US
 +
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 +
update_config=1
 +
network={
 +
        ssid="YOUR_SSID"
 +
        psk="YOUR_PASSWORD"
 +
        key_mgmt=WPA-PSK
 +
}
 +
</source>
 +
 +
Then mount the primary partition and run in terminal:
 +
<source>
 +
cd /your_mountpoint/etc/ssh
 +
sudo rm ssh_host_*
 +
</source>
 +
 +
Now run these commands to set up <code>dpkg-reconfigure</code> to run on startup:
 +
<source>
 +
cd /your_mountpoint/etc
 +
sudo sed -i 's/exit\ 0/dpkg-reconfigure openssh-server\nexit\ 0/g' rc.local
 +
</source>
 +
 +
When you start up the Raspberry Pi, you should be able to SSH into it immediately after everything runs (and once you figure out what the IP address is).
 +
 +
Remember, it's easy to figure out the IP using:
 +
<source>
 +
sudo nmap -sn 192.168.0.0/24 | grep -A1 Raspberry
 +
</source>
 +
 +
Once you've logged into the Pi, you can remove the <code>dpkg-reconfigure</code> in rc.local:
 +
<source>
 +
cd /etc
 +
sudo sed -i 's/dpkg.*//g' rc.local
 +
</source>

Revision as of 21:51, 12 June 2019

I'm very annoyed that I can't just throw a Raspbian image onto an SD card and SSH into it without pulling out an HDMI monitor and keyboard. I finally have all the steps necessary to get it done. These steps were done on Raspbian Jessie 2017-07-05.

Image the SD card:

sudo dd if=imagefile.img of=/dev/yourdevice conv=notrunc,noerror ; sync

Now mount the "boot" partition of the SD card (you could just remove the SD card and insert it again).

In the boot partition, create an empty filed called "ssh" (with no file extension).

(Optional WiFi) Create a file in the boot partition called "wpa_supplicant.conf" and enter this content:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
        ssid="YOUR_SSID"
        psk="YOUR_PASSWORD"
        key_mgmt=WPA-PSK
}

Then mount the primary partition and run in terminal:

cd /your_mountpoint/etc/ssh
sudo rm ssh_host_*

Now run these commands to set up dpkg-reconfigure to run on startup:

cd /your_mountpoint/etc
sudo sed -i 's/exit\ 0/dpkg-reconfigure openssh-server\nexit\ 0/g' rc.local

When you start up the Raspberry Pi, you should be able to SSH into it immediately after everything runs (and once you figure out what the IP address is).

Remember, it's easy to figure out the IP using:

sudo nmap -sn 192.168.0.0/24 | grep -A1 Raspberry

Once you've logged into the Pi, you can remove the dpkg-reconfigure in rc.local:

cd /etc
sudo sed -i 's/dpkg.*//g' rc.local