Ssh authorized key

From Tekkotsu Wiki

Jump to: navigation, search

Normally when you ssh into a robot or copy over a file using scp, you must type your password to proceed. However, if you establish an ssh authorized key, you will no longer have to type a password. This is especially useful if you want to use a shell script to copy files onto the robot, since now the script can include multiple scp operations and you don't have to type even one password.

In your home directory there is a folder named .ssh. To see it you must type "ls -a". If it's not there, you can create it by running ssh. There should be a similar directory on the robot, and again, you can create it if it's not already there.

Creating a public/private key pair

These instructions apply to Ubuntu 10.04, but will probably work on any recent Linux distribution.

1. Generate a key pair on your workstation by typing:

cd ~/.ssh
ssh-keygen

When prompted for where to store the key, say: "robots_id_rsa". Use an empty passphrase. This will create two files in your ~/.ssh directory: robots_id_rsa and robots_id_rsa.pub.

2. Let's assume you have three robots named Robot1, Robot2, and Robot3, and your login name on these robots is "user". Create a ~/.ssh/config file on your workstation with the following contents:

Host Robot1 Robot2 Robot3
 User user
 IdentityFile ~/.ssh/robots_id_rsa

3. Install the public key as an authorized key on each robot. Assuming you don't already have a ~/.ssh/authorized_keys file on the robot, you can just copy over the public key like this:

scp ~/.ssh/robots_id_rsa.pub user@robot1:.ssh/authorized_keys

If you do have an authorized_keys file you will need to copy over the robots_id_rsa.pub file and then log in to the robot and append this file to the existing authorized_keys file.