Rackspace Cloudvent Calendar Day 2: Automating SSH Keys

In the spirit of the holiday season, I’m sharing some tips and features of our cloud that you may not know about. In this countdown I’ll have 24 posts for you, each covering a single topic or feature about Rackspace Cloud products. We’ll post one per day so keep checking back!

Setting up SSH keys to use with your Cloud Servers is easy and makes login a snap. You’re going to need the rackspace-novaclient installed – you can find the instructions here. Be sure you set up your .bash_profile with variables that match your account.

Once you have the client installed, you need to generate a SSH key. This step can be skipped if you already have a key that you want to use. Open up a terminal and issue this command:

ssh-keygen –t rsa

This will generate two files: your public key and your private key. Your private key should NEVER be shared with anyone. NEVER EVER. Not even with us. The terminal will prompt you on where you want to save these files, and for a password. If this is your first SSH key, the default locations are fine. You don’t need a password if you don’t want one – just hit enter to accept the defaults.

So now you have two files: ~/.ssh/id_rsa (Private) and ~/.ssh/id_rsa.pub (Public). Let’s upload your PUBLIC key to your account with the nova client:

nova keypair-add --pub-key ~/.ssh/id_rsa.pub mykey

Congrats! You’ve just added your key to your account. Now you can build a server with that key already in place:

nova boot -–image <UUID> --flavor <FLAVOR> --key-name mykey SERVERNAME

The server will be created and have your public key in your authorized_keys file. Now when you SSH to the server, you won’t be prompted for a password.

Did you miss day 1? You can read it here. Check back tomorrow for day 3!



Please enter your comment!
Please enter your name here