On standard cloud images of Linux operating systems like Ubuntu and Fedora SSH access is restricted to public key authentication. Instead of authenticating with a password you authenticate with a private key that corresponds to a public key that is installed on the instance.
Jan 31, 2010 I wanted to use the key I generated using the PuTTYGen tool on my windows laptop, on my now repaired Mac Pro. The standard PuTTY generated key will not work on Linux or Mac OSX, so the key needs to be converted into a standard that will, like OpenSSH. You can convert your key.
This HOWTO explains how to use keypairs in OpenStack and how to log in with Putty, a SSH client that runs on Windows. Most steps have to be completed once to get you going.
Note
This HOWTO assumes you have an OpenStack account and the OpenSSH client installed.
Creating a Keypair
If you haven’t created a key before, start with creating a Keypair in OpenStack:
Go to ‘Access & Security’
Open the ‘Keypairs’ tab
Click on the Create Keypair button:
Choose a Keypair Name:
You will now be asked to save a .pem file. Save the file on a convenient location. You won’t be able to download it again.
Open a terminal
Correct the file permissions of the .pem file
For example:
Inserting a key in a new instance
In order to be able to use the key, you need to insert it in a new instance in OpenStack:
Open the Instances menu on the left
Click on Launch Instance
Choose the relevant options in the Details tab
Select the keypair that you just created:
Complete the rest of the wizard
Associating a floating IP address
To be able to access an instance remotely, a floating IP address needs to be associated to the instance.
Associate a Floating IP address to the instance, by clicking the 'Associate Floating IP' option in the menu on the right:
Pick a Floating IP address from the drop down menu. If no address is available, add one by clicking the + button:
Using the key with OpenSSH
Now we've prepared a key, started an instance and associated a floating IP we can use the key to login the instance with SSH:
Open a terminal
Start a SSH connection with a command like the one below (default username depends on the image, on Ubuntu the username is simply 'ubuntu'):
For example:
Optionally, you can use the SSH configuration file. Add the following to ~/.ssh/config:
After that you can simply login with:
If you have connected to a server with the same IP address before, you'll receive a message like the one below.
When you're connecting to a new instance you can delete the offending key with this command (change the line number to the one in the warning message):
When connecting for the first time you'll be asked the following question. Type 'yes' to continue:
If everything works alright you’re now logged in.
SSH keys are an access credential used in SSH protocol (Secure Shell) which is a network protocol that helps to login from one computer to another securely, as well as to manage networks, operating systems, and configurations. This snippet is going to help you add an SSH key to the ssh-agent, generate a new SSH key, learn how to find the SSH key of your PC and how to connect it with your GitHub/bitbucket account. You can also find information on the use of SSH keys.
Now let's find out how we can checkout PC's SSH keys.
Checking PC's SSH Keys
Type ls -al ~/.ssh so as to see your ssh keys:
By default, the filenames of the public keys are one of the following:
Generate a new SSH key
Type this below, using your GitHub's account email:
The following text will show up after which you can hit the “Enter” button:
In this section, you can hit “Enter” again or type the secure passphrase (more about passphrase).
Adding an SSH key to the ssh-agent
Now let’s find out how we can add the SSH key to ssh-agent. Before adding, check your ssh keys or generate a new key.
- Be sure ssh-agent is enabled:
- Add your SSH key to the ssh-agent. If you used an existing SSH key rather than generating a new SSH key, you would need to replace id_rsa in the command with the name of your existing private key file:
How To Add SSH Key To Github Account
- Log into your Github's account. In the top right corner of any page, click your profile photo, then click Settings.
- In the user settings sidebar, go to SSH and GPG keys.
- Click New SSH key.
- Type Title and your SSH Key.
You can get your ssh key by typing below.
Now you have added your PC's SSH key to your Github's account.
Back up old SSH keys
If there are existing SSH keys, but you do not want to use them for connecting to Bitbucket Server, you should back up these old keys running the following:
Why we need SSH key (for Linux and OSX)
If you use Git and want to clone anything from remote repositories, you have to choose one of these two ways: HTTPS or SSH. If you use HTTPS, you have to type your account access every time you communicate with the remote repository, or change your configs and fill your account data (access). Another modern way is to use the SSH authentication method. It is used in many Version Control Systems to have command line access into your servers, etc. SSH key pairs can be used for authentication instead of passwords. Each key pair consists of a private key and a corresponding public key. When you use SSH key for Git, you inform Git that this PC is authenticated for that Github account, and it will never ask you about any access again because you have already given it your SSH key.