Close

Image and Configuration

A project log for Octoprint

My process for setting up and configuring Octoprint on a Raspberry Pi.

lazLaz 01/22/2015 at 03:140 Comments

I started the process by downloading the latest image of octoprint. I've tried starting with more general images and pulling the requisite packages in, but I end up with lots of stuff that I don't want on my card. You can start by finding the most recent image linked from Octoprint.

Getting the image on the card was accomplished through the "dd" tool from linux command line. The raspberry pi foundation has a great tutorial on their webpage, located here.

With the image now loaded on the card, I put it into the Raspberry Pi and booted it up. By default, the image is set up to run raspi-config on the first boot. For this boot, you need to have a mouse, keyboard, and monitor connected to the Raspberry Pi. During that first setup, I changed some stuff to make that unnecessary. Here is the list of things that I changed:

At this point, I'm ready to reboot my RPi. The reboot this time takes me to user log-in. The default user is pi, and the default password is raspberry (but hopefully you changed this). The plan is to use SSH to allow us to connect to the Octopi without having a mouse, keyboard, and monitor connected. Right now, the SSH is enabled, so I can connect to my Octopi by typing "ssh pi@octopi" and being prompted for my password. There are still some steps to take for convenience and security.

The plan is to add a user with the same username that I have on my laptop. That way, when I SSH into the Octopi, I won't have to specify a username. Again, Raspberry Pi Foundation to the rescue! See page here. After adding my new user, I'll add the user to the list of sudoers, still following directions from the last link. At this point, I should be able to SSH into my octopi from my network by typing the command "ssh octopi", no "user@". It will however ask me for a password, and that's the next thing to change.

Now that I have a user with the correct credentials and permissions, the next thing I want to do is create a set of SSH keys for that user. I don't like using passwords for SSH authentication because it's relatively insecure. Using keys takes a little bit of setup, but saves time in the long run because you won't have to worry about remembering or using passwords.

For this process, Github has a great tutorial to describe how to set up SSH keys here. If you've never done this from your computer, you'll need to follow the key generation process on your computer first so you'll be able to have a key pair that you can use for authentication from your computer to any other computers, such as your Octopi. Their tutorial is a bit specific to using with Github. Once I've created the key pair on my Octopi, I want to copy the public key to the authorized_keys file to any computer that I want my Octopi to be able to SSH into. Likewise, I want to send the public key of my laptop to the authorized_keys file of my Octopi. There is a command all set up for this: ssh-copy-id. Since I've already set up a user with the correct name, I can simply type in "ssh-copy-id octopi". I'll be prompted for my password one last time, then my public key will be pushed into my Octopi's authorized key list. At this point, I can now ssh into my Octopi by typing in "ssh octopi" and it'll connect and authenticate using my key pair and never ask me for a password again. Ta-da!

Now, that we can ssh into the octopi with key-based authentication into our newly created account, and the account has sudo access, we want to remove the ability to log into ssh using passwords at all. Right now, if someone had access to the network the Octopi is on, they could try to brute-force guess the password for the newly created account, or the default pi account. Since we don't have to type in passwords anyway, we're going to go ahead and disable the ability to enter passwords all together. The way to do that is to edit the file "/etc/ssh/sshd_config". Ubuntu has a good tutorial for that. You can find it here. There are lots of settings you may want to change, but the important one is to change the line about password authentication to say "PasswordAuthentication no".

Now that all those configurations are complete, we can tell our Octopi to restart by typing in "sudo reboot" and it'll reboot. Once it's back up, you should be able to ssh into it with the command "ssh octopi" and not be asked for a password. If anyone tries to connect and doesn't have a key on the authorized_keys list, then the Octopi will immediately close their connection. No chance to try to brute force the password.

After rebooting, the Octopi should be all set up and ready to use.

Discussions