How to use SSH authentication keys on Cloud Containers

Created by Jordy Leffers at 06-12-2017 11:05:35 +0100

Secure Shell Keys are one of the most common ways to securely connect to a remote machine. If you're a customer at cloudcontainers, you will have already seen the term pass while creating a virtual machine. The keys allow an authentication mechanism without, by definition, always requiring a password. This will help speed up logging in or connecting to your virtual machines, which is why it's such an attractive option for a lot of people. In this guide we'll go over how to exactly create an SSH-key and how to configure your containers to use it.


Generate your SSH-key

Generating an SSH-key differs a little per operating system, your terminal program might differ for example. That's why we've chosen to split this tutorial up into three parts, for the major operating systems. Click the link to the tutorial on how to generate your SSH-key for your according operating system: Windows, Linux or mac.

Come back to this page once you've got your SSH-key!


Upload the public key to your container

Now that we've generated our keys, we will want to upload them to our container so they can be used to log in. There are two ways to upload your public key for your containers in order to use them to verify remote connections:


Add the key to your Cloudcontainers account

Now add your public key to your Cloudcontainers account, so your VM's will know what to verify your personal keys with. Go the your account page, if you're logged in you should be able to use this link: https://my.cloudcontainers.net/#/account 

Navigate to the tab: "SSH keys".  Give the key a name by filling in the "Key name" field, you can name it whatever you want but if you have a lot of keys, you should probably name it something that'll help you organize them a bit.

Next, open the .pub file and copy its content. It will look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8dE2kSX+e/bNDiEt9GqjnQWhMOXp7hycSrZO+49nDK/pX1rN+WGuWh6rTr0LKYNen+hJjFOilzBqoyHI90+ndOD+aMjOxWh9YzY/7DmUUqd49I33unCVSlCB95ts2uING2aWJQQ/tV+g+BQXQ0fUljBw59lAu42bvVvxHPI+ot+LvQ2FYRT9sJZwj2nxuGDXyYRXOYqcFF5yIqvLQEL2id+Jp0/V1hkjlyG/7rUVNrAdRGKyHGtrT9/Lu10WJuJr7FfT/P8/5UXd++K3DUrRcqqCUefwSHnAIT8K9eGWkryUviN+t8B60hdqrh7qA6FbckKGd9sRcDCob57BbRQqf klaas@KARL

Paste it in the "Key value" field.

You should now be able to use this key to make a connection to new virtual machines you make.

ssh -i ~/.ssh/id_rsa root@82.97.163.68


Add the key to an existing machine

If you already have a machine running that you want to add your key to, we'll need to modify the "authorized_keys" file on the machine. Obviously, this is option only possible if you already have acces to the machine using another key.

First, open the .pub file and copy its content, it will look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8dE2kSX+e/bNDiEt9GqjnQWhMOXp7hycSrZO+49nDK/pX1rN+WGuWh6rTr0LKYNen+hJjFOilzBqoyHI90+ndOD+aMjOxWh9YzY/7DmUUqd49I33unCVSlCB95ts2uING2aWJQQ/tV+g+BQXQ0fUljBw59lAu42bvVvxHPI+ot+LvQ2FYRT9sJZwj2nxuGDXyYRXOYqcFF5yIqvLQEL2id+Jp0/V1hkjlyG/7rUVNrAdRGKyHGtrT9/Lu10WJuJr7FfT/P8/5UXd++K3DUrRcqqCUefwSHnAIT8K9eGWkryUviN+t8B60hdqrh7qA6FbckKGd9sRcDCob57BbRQqf klaas@KARL


Next, open the "authorized_keys" file on the server using the following command:

nano /root/.ssh/authorized_keys


Here we can paste our public key, afterwards save and exit the file.

You should now be able to use this key to make a connection to the virtual machine:

ssh -i ~/.ssh/id_rsa root@82.97.163.68


Thank you for reading this tutorial!

Comments

Comments are turned off.