Raspberry Pi – SSH and static IP

By the time I received my RasPi, I didn’t have an usb keyboard yet, so my first concern was about how to use it without the keyboard from the very first boot. It wasn’t clear whether the ssh daemon would be active by default or not, and I’ve also got to know that for some distributions, or even among different updates of the same distribution, its default state changed over time.
I found out that in Raspbian, ssh is installed by default but it’s not configured to start up automatically since the first boot.

Being it a SystemV style OS, I proceeded as follow to enable the ssh daemon at boot.
After plugging the SD card in, and mounting the system partition on the SD card to my Fedora installation, I created the symbolic links for ssh to start at boot time as follows:

# ln -s etc/init.d/ssh etc/rc2.d/S02ssh

and repeated the process for the other runlevels of interest, in my case from 2 to 5.
Now the ssh service would start at boot time and would accept incoming connections.

I could have stopped here with the configuration to be able to access my brand new Pi, but I also wanted to configure the network with a static IP, for my own convenience and ease of NAT rules configuration on the router.
Raspbian comes with the nano text editor, so let’s get into the interface configuration by editing the config file as follows:

# nano etc/network/interfaces

change the iface eth0 inet dhcp line to iface eth0 inet static and add the further details:

address 192.168.1.xxx

Where xxx is the last byte of the local ip of your choice.
Adapt the lines above to your actual network configuration, your router may have a different ip/submask to deal with.

Now it’s time to boot the Pi and connect to it via ssh:

$ ssh pi@192.168.1.xxx

or if you need to use graphical applications

$ ssh -X pi@192.168.1.xxx

Note that the default pair of user/password for Raspbian is:

user: pi
password: raspberry

Very important note: once you get access to your Pi, do regenerate the SSH keys.
Since Raspbian (and basically all the other distributions) are distributed as prepared images to copy onto the SD card, it is not safe to keep the default SSH keys.
To regenerate the keys proceed as follows:

# rm /etc/ssh/ssh_host_*
# dpkg-reconfigure openssh-server


Leave a Reply

3 thoughts on “Raspberry Pi – SSH and static IP

  • nicolas

    i have the same problem, no keyboard!
    Iam trying to follow what you’ve done, unfortunately iam stuck when i try to mount the system partition (i guess you meant the kernel.img), on my osx. I just have an error saying the system can’t recognize this image …
    Do you know how i could mount this file easily ?


    • SLB Post author

      Hi, I edited the files straight from the SD card. You can just write the image on the SD first with dd, or equivalent tools.

Loading Facebook Comments ...