There are two options to create virtual machine (Linux VMs) in Azure ARM (Azure Resource Manager). One with password and second with public key. When VM is created with password access there is needed to enter password via ssh. Another option is to connect without password. Just having public key stored in file.
Before creating Linux VM there is needed to generate public and private key. First update your packages ssh-keygen and openssl:
$ sudo yum update openssh $ sudo yum update openssl
Then create 2048 bit RSA public and private key files:
$ ssh-keygen -t rsa -b 2048 Generating public/private rsa key pair. Enter file in which to save the key (/home/centos/.ssh/id_rsa): Created directory '/home/centos/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/centos/.ssh/id_rsa. Your public key has been saved in /home/centos/.ssh/id_rsa.pub. The key fingerprint is: e5:df:3a:b5:08:23:34:06:66:16:5b:c6:dc:57:7b:80 centos@cent7 The key's randomart image is: +--[ RSA 2048]----+ | .+o. oo | | =+o . E o | | +.. .. . .| | +o . | | oS.. | | . o. .. | | . o.o.. | | o.. | | .. | +-----------------+
This is it. You can use ~/.ssh/id_rsa key for connecting to the remote VM via ssh. The key ~/.ssh/id_rsa.pub will be used to enter in Azure VM wizard.
Now we can create virtual machine in Azure mangement portal.
1. Go to the Azure Management ARM portal and login
2. On the left side click “New” then select Compute and click “See all” link
3. In the search filter enter OS name, in my example it is CentOS 7.1 and click on the name that appears
4. Make sure that Resource manager is selected in the deployment model
5. In the next step, Basic configuration panel opens. Enter public key ~/.ssh/id_rsa.pub in the SSH public key field
$ cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdI1DVrCimmDzy8mu7ZGwAWkOgQQ6j0zyNVCLOOjwhpycRU7/+9+fIHe1I0Xe3n/wKHcfmPBvfbyeO/1znAcAPooTe8TFR606webo0QtUCiHtjmrSw7ZlZxjdc/dMgSHLwLQn7cm9N4yj/u3B5jBgJsQAOfScFX6nZe2OoakjuCDbHtfRjr3f3WIQlTLcvzy8S23JxlSrnNYsIrT6ePOlMz0C7YHH1AKPrJqFUi3cL3JqsLK2FElT2ARnd2uiXKA//bLTREzdTNWQAmXUaRbB3YQ9xiJ/nNIoi0M1VMghDRbMYxhnvKc+ykwGbm5SqUs63xOxnFFzPTiyG8ASHJREL centos@cent7
6. Select Virtual Machine size. I selected A1. If you do not have subscription there is option for a free VM
7. In Settings all items could be as default
8. In the summary panel make sure that all data is ok
9. At the end VM is deploying in the Azure ARM. Wait until the VM is deployed.
Now you can test the passwordless connection from your host to the VM in Azure ARM. By default you do not have to enter name of the private key. But if you want to move the key to the different location you can use -i option:
[centos@cent7 ~]$ ssh -i .ssh/id_rsa [email protected] Last login: Wed Feb 10 22:05:49 2016 from IP.hostname [centos@cent5 ~]$
Tutorial on youtube:
References:
https://azure.microsoft.com/pl-pl/documentation/articles/virtual-machines-linux-use-ssh-key/
Leave a Reply