原理:
本地用gitbash和puttygen創建私鑰和公鑰,在創建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,輸入用戶名,就可以看見命令行了