【Azure】使用ssh创建访问Linux虚拟机

原理:

本地用gitbashputtygen创建私钥和公钥,在创建Linux VM时将ssh公钥上传,在PUTTY用私钥登陆连接到Linux VM

 

准备:

1.Git Bash for Windows

2.PUTTYGEN.exe

3.PUTTY.exe

4.Azure订阅 (Azure Resource Manager

 

步骤:

一.Git Bash创建私钥

1.输入指令:


此例中密钥名为myPrivateKey,证书为myCert.pem

openssl.exe req -x509 -nodes -days 365 -newkey rsa:2048 \-keyout myPrivateKey.key -out myCert.pem

2.得到以下类似的提示

Generating a 2048 bit RSA private key

.......................................+++

.......................+++

writing new private key to 'myPrivateKey.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:

 

按照提示填写一系列信息,包括国家,地区,公司及个人信息等。

 

3.在当前工作目录中得到了私钥和证书文件

 

4.运行命令:

openssl.exe rsa -pubout -in myPrivateKey.key -out myPublicKey.key

得到一个名为myPublicKey.Key的公钥文件

 

 

二.PUTTY创建私钥

1.使用Git Bash将私钥转换为Puttygen可识别的RSA私钥。

前提:名为myPrivateKey的现有密钥

bash上运行:

openssl rsa -in ./myPrivateKey.key -out myPrivateKey_rsa

得到名为myPrivateKey_rsa的密钥

 

2.使用Puttygen

点击Flie”——“Load Private Key

 

3.找到刚才生成的私钥(这里是myPrivateKey_rsa

注意:文件筛选改为AllFile,如图

默认路径为C:用户(user:%用户名%myPrivateKey_rsa

 

 

4.单机“打开”,弹出提示,点击确认。


5.公钥就显示在界面里


 

6.创建VM时,把ssh公钥复制,添加到如图的位置

 

7.Puttygen保存私钥

点击Save Private Key”,

显示一个提示,询问是否想要继续,而不输入密钥的通行短语。

点击是,如果要添加点击否。

 

8.输入名称得到<xxxx>.ppk文件


三.PuTTy连接到Linux vm

1.http://putty.in51.com/download.html下载putty

2.打开putty客户端,输入在Azure门户上创建的虚拟机的IP

 

 

3.点击connection——SSH——Auth

 

 

4.找到刚才生成的.ppk文件选择。

 

5.Open,输入用户名,就可以看见命令行了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章