IBM Bluemix Linux VM 配置秘钥并登录

IBM Buemix  Linux虚拟机的登录问题.

如果使用Ubuntu等linux系统登录,直接使用ssh命令即可访问bluemix上的Linux实例:
  ssh -i XXX.pem ibmcloud@{IP/hostname}  (XXX.pem 是你在Bluemix上创建虚拟机时Bluemix为你自动生成的私钥文件,你应将此文件保存)

从windows机器登录,需要使用SecureCRT,Putty,SSH secureShell client 等工具。但生成的密钥文件,不能直接在这些工具里或者服务器端使用,需要做一些处理才可以。下面给出几个从windows上登录的方案

方案一 使用putty+FileZilla (创建虚拟机前准备好密钥,在创建过程中导入公钥)

1. Download the FileZilla and putty ( http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html, both putty.exe and puttygen.exe   )

2. Run puttygen.exe to generate the private key (.ppk file), public key(.pub file) and the public key for openssh. Save all 3 parts into 3 different files (such as key.ppk, key.pub, key-openssh.pub)

 Please drag your mouse to increase the speed when generating the keys.(也可以指定密钥密码为空,以便实现无密码登录)

3. Login to IBM Bluemix, https://console.ng.bluemix.net/ , to create the VM:

    when in Create VM->Security Keys->Add key ->select Import , then paste the content of public key for openssh to the section of  "Public Key to import"

Make sure the VM has public IP.

Please remember that the default user id is ibmcloud for created VM.

4. Use putty to login :

 edit an BAT file, such as login_Bluemix.bat :  putty -i  key.ppk  -l   ibmcloud  192.168.0.9(your VM public IP) 

直接运行login_Bluemix.bat ,进入后会提示让你输入key的密码,输入你在step 2 中产生private key密钥的密码,即进入系统shell(如果密钥的密码在产生密钥时 指定为空,则是无密码登录)。

5. Configure the FileZilla to use key authentication:

Open FileZilla, in menu click Edit ->Setting dialog->Connection->SFTP->click Add Key File , to add the generated private key file in step 2.

Create the new site to your FileZilla:  Host 输入你虚拟机的公共IP,  servertype 选择sftp , logontype选择Normal , User输入ibmcloud

你会发现现在可以无需密码进行文件传输。

方案二 使用SSH secureShell Client

在方案一的基础上(已经能登录),改用SSH secureShell.

1. 先用SSH SecureShell client 产生密钥(公钥和私钥)。

 Edit->Setting->Global Setting -.> User Authentication -> Keys ->Generate New

2.将公钥放到服务器的 ~/.ssh  , 执行 ssh-keygen -i  -f  publicKeyFile >> authorized_keys (可利用方案一来登录到远程服务器)

3. 在登录时选择机器,用户名ibmcloud,端口号22, 认证方式Authentication Method选择public key

方案三 直接使用SSH secureShell client

对比方案一和二,可以发现方案一产生了三个文件而方案二产生了2个文件后再执行ssh-keygen -i  -f  publicKeyFile >> authorized_keys 把公钥转换成了openSSH使用的公钥,从而解决问题.

因此,可直接在SSH SecureShell产生秘钥(或者使用GUI ,或者使用ssh-keygen2.exe命令行),然后将公钥在某个配置了openSSH的 Linux机器上转换成openSSH公钥,之后再到Bluemix创建虚拟机时,选择Import,将转换成的openSSH公钥黏贴进去作为key. 这样就可直接使用SSH SecureShell登录。

(此方案的优点是无需登录远程虚拟机,只需任何装了openSSH的linux机器即可)


前三个方案是创建虚拟机前准备好密钥,在创建虚拟机时导入密钥。 而Bluemix VM还提供了另一种方式是在创建VM时Bluemix自动生成密钥(PEM格式私钥,创建时会提示你下载到本地).方案四解决这种情况.

方案四 使用VM生成的密钥,

4.1 利用SecureCRT访问虚拟机.

1)从Bluemix虚拟机的PEM格式私钥读出对应PEM格式公钥 

ssh-keygen -y -f  Key.pem >Key.pub

将key.pem和key.pub放在同一目录

2)安装并运行secureCRT,

选protocol为 SSH2,输入主机,在Authentication中将publickey排在第一位,选中publickey,点击properties,在public key property窗口,浏览到指定的pem文件。

然后点connect ,根据提示输入用户名,就会进入系统。

4.2 使用putty和 puttygen,

1) 使用 puttygen的Load existing private key 功能来生成putty使用的ppk格式的私钥。

运行puttygen.exe , 点load,文件类型选所有,选择之前下载的VM的私钥文件,并将生成的ppk格式私钥和公钥保存起来。

2)写脚本类似如下 C:\devtools\putty -i Ce1Key_ByPutty.ppk -l ibmcloud  129.41.xx.xxx(机器IP)

Ce1Key_ByPutty.ppk是转换成的putty ppk格式私钥文件

运行脚本, 即可进入虚拟机.

4.3 使用cygwin.

既然Linux机器可以利用pem秘钥文件很自然方便的登录Bluemix的Linux VM, 那么在Windows安装一个cygwin来登录Bluemix Linux VM也是可行之道 (因为cygWin是windows上的linux,其具备一般linux的功能,当然也能登录远程linux机器)

1) 把pem文件放到cygwin下某个目录

2)确保cygwin安装了openssh,scp等功能

3)进入cygwin执行如下命令:

ssh -i xxx.pem  ibmcloud@host (远程机器IP)

即可实现远程登录

如果需要文件传输,可以考虑使用scp :

拷贝本地文件到远程机器:scp -i XXX.pem   myFile  ibmcloud@IP:/home/ibmcloud/ (拷贝到/home/ibmcloud/, 可根据需要修改)

拷贝本地目录到远程机器:  scp  -i XXX.pem -rp  myFolder  ibmcloud@IP:/home/ibmcloud/ (拷贝到/home/ibmcloud/, 可根据需要修改)


备注:

FileZilla   :开源免费版,主要用于文件传输,GNU GPL许可证,客户端可用于Windows , Linux, MacOS  。  https://filezilla-project.org/download.php

Putty: 开源免费版,主要用于远程登录,MIT许可证,客户端可用于Windows , Linux, MacOS。   http://www.putty.nl/

SSH secureShell Client: 免费版,文件传输和远程登录二合一,客户端可用于Windows , Linux, MacOS.   下载 http://www.wm.edu/offices/it/services/software/licensedsoftware/webeditingsftp/sshsecureshell/index.php

secureCRT : 商业收费版,使用需考虑价格。客户端可用于Windows , Linux, MacOS.  http://www.vandyke.com/products/securecrt/

Bluemix : https://console.ng.bluemix.net/ ,IBM的云计算平台,可以创建应用(个人博客,论坛等Web应用),容器Container , 虚拟机等等各种云端产品。是IBM今年的发力之作。




   



猜你喜欢

转载自blog.csdn.net/tonyhuang_google_com/article/details/45749375