The.pub file is your public key, and the other file is your private key. If you don’t have these files (or you don’t even have a.ssh directory), you can create them by running a program called ssh-keygen, which is provided with the SSH package on Linux/Mac systems and comes with the MSysGit package on. Nov 10, 2011 How to Generate A Public/Private SSH Key Linux 1. Open a terminal. In the next screen, you should see a prompt, asking you for the location to save the key. Next, you will be prompted to enter passphrase. Your public and private SSH key should now be generated.
One effective way of securing SSH access to your cloud server is to usea public-private key pair. This means that a public key is placed onthe server and a private key is placed on your local workstation.Using a key pair makes it impossible for someone to log in by using justa password, as long as you set up SSH to deny password-basedauthentication.
This article provides steps for generating RSA keys by using PuTTYgen onWindows for secure SSH authentication with OpenSSH.
In Windows, use PuTTYgen to generate your public and private keys.
You can use the RSA key pair in the following ways.
When you create a cloud server, you can assign a public key from the list of keys.If your key is not already in the list, you may add it, and then assign it.
Add a new public key to the list
Assign a public key
To make use of your newly generated RSA key pair, you must tell PuTTY touse it when connecting to your cloud server.
To edit the file (or create it), run the following command on the cloud server:
Paste the text onto its own line in the file.
You must have the key available in your clipboard to paste it. The key and itsassociated text (the ssh-rsa identified at the start and the comment at the end)must be on one line in the file. If the text is word-wrapped onto multiple linesan error might occur when connecting.
If you created the authorized_keys file, change its permissionsafter you’re done editing it by running the following command:
Open PuTTY, and go to the SSH > Auth section.
Browse to the location of the key file, and load the private key.
Go to the Session page, and save the session. This saves the configurationso that PuTTY uses the key every time that you connect to your cloudserver.
After you save your session, your key is loaded automatically when youconnect to your server.
©2020 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License
SSH KEYS allow us to connect to VMs without using passwords but by passing a private key that can be managed by you or your organization.
There are three parts to this tutorial:
A. Generate an SSH Key
B. Create a VM in Azure that uses the public key
C. Connect to VM using SSH keys
Prerequisites:
Bash
ssh-keygen ($ info ssh-keygen to learn more)
An Azure Subscription
A. Generate an SSH Key
Open bash and enter:$ ssh-keygen -t rsa -b 2048 -C 'Ubuntu@azure-server'
Keyname: server-key
Passphrase: somethingMemorable
Copy the contents of server-key.pub$ cat server-key.pub
Should look like this:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMlUr7PCEdBmCVZHG5RqI8i7GgYAzd2G/FZ987XXa63vnqxZmZogVmmXrTnBHeM6oDv7v7g495CiiiINhJbGR4o7t4agiHOM43egDv7BbiViTlfVr3y5AxLUvRwHnC3egl8ABVX1anfXXR73x7IS3YRNWkh6gXtlhImw8UKG04UoZEmWB9BLt53lk/9c3Hxz22YZarzImrpQYy1XEUZ096B9mK/Fe+/McH78ZHUpXEgOZBIDP5KdqPk5XKznpwUDJ4/SPXPEWWCCjQ8gOoTFcFMaiMnXp5o5Udsi/DFO1TS/t8BeCRymkr5tdPvzexjkjkjkjkjkjkjkjkjkjkjkjt Ubuntu@azure-server
Here’s what it looks like for me:
Cool and you’ll also notice that there’s another file in that same directory – server-key$ ls grep server
Here’s what that looks like for me:
Now that we have our public and private keys let’s get our VM setup.
B. Create a VM in Azure that uses the public key
64 bit encryption key generator. 1. Go to the Azure Portal
2. Select New -> Search: Ubuntu Server
(I’m using 14.04 this time)
3. Make sure you’ve selected Resource Manger and click Create:
4. Now configure the basics per our ssh-keygen parameters
Name: azure-server
VM Disk Type: Up To You
User name: Ubuntu
Authentication type: SSH public key
SSH public key: Paste the results of $ cat server-key.pub
Subscription: Depends how you want to pay for the server
Resource Group: Up to you – I’m going to create a new one so I can quickly delete it.
Location: Up to you
Should look like this:
Then select OK to go to the next section.
5. Choose Virtual Machine Size
I’m going with the smallest VM for testing.
You can also view all different VM sizes to find the right one for your use case.
6. Configure optional Features
Setting the Storage account name to something you’ll remember easily is good.
And if you want to configure ports now you can select Network Security group to allow ports specific traffic.
Here’s what that looks like:
Click okay to continue to the Summary of your VM.
Here’s our summary:
Select okay to start your VM.
7. Wait for it to be ready.
Dashboard will have an icon and you’ll get a notification when its ready:
8. Once ready select on it to see the overview and the IP address.
Should look like this:
Great! We have a VM and its IP address. Lets use our Private SSH key to connect.
C. Connect to VM using SSH Keys
1. Open bash to file location you created the keys in.
Make sure they’re there:$ ls grep server
2. Enter this command to use SSH to connect:$ ssh -i server-key Ubuntu@52.183.31.11 -v
or more generally$ ssh -i keyname username@ip.address -v
Make sure you’re using server-key and not server-key.pub
Tip: -v is the verbose option. Not necessary, but it helps to see if the key is being accepted
3. Great, now accept the certificate, and enter your memeroablePassphrase
Whole thing should look like this:
And you’ll be in the terminal of your VM:
Yay!
You’ve got the key, you’ve got the VM, now put it to work!
Flask on Ubuntu
Node on Ubuntu
Mongo on Ubuntu
Connecting to VMs from Azure Web Apps
Let me know if you have any questions by posting in the comments below!