从客户端来看,SSH提供两种级别的安全验证。
Pasted from
Q:实现物理机无密码访问其上起的虚拟机?
A:使用ssh密钥的安全验证
物理机:ssh客户机
root@yourong:~# hostname -I
10.239.131.211 192.168.122.1
虚拟机:ssh 服务器
root@yourong:~# virsh list --all
Id Name State
----------------------------------------------------
47 sqlrabkey running
48 aquantum running
49 quantum-netnode running
以虚拟机sqlrabkey为例。
root@sqlrabkey:~# hostname -I
10.239.131.210 192.168.222.4 192.168.111.4
1> 在物理机上创建公钥
ssh-keygen-t rsa
-t 指定密钥类型,默认即 rsa ,可以省略
Generating public/private key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
一直enter。
2> 将公钥复制到虚拟机sqlrabkey下
ssh-copy-id -i ~/.ssh/id_rsa.pubroot@sqlrabkey
报错:ssh: Could not resolve hostnamesqlrabkey
3> 添加ssh服务器(即sqlrabkey)信息到客户机的~/.ssh/config配置文件下
vim ~/.ssh/config #若没有该文件,直接新建即可
添加文件内容格式如下:
Host alias #自定义别名
HostName hostname #替换为你的ssh服务器ip或domain
Port port #ssh服务器端口,默认为22
User user #ssh服务器用户名
IdentityFile ~/.ssh/id_rsa #第一个步骤生成的公钥文件对应的私钥文件
Pasted from
此处添加上:
Host sqlraqkey
HostName 10.239.131.210
Port 22
User root
IdentityFile ~/.ssh/id_rsa
保存退出,在执行第2步,就好了。
配置好以后,就可以不输入密码从物理机ssh到虚拟机了。
root@yourong:~/.ssh# ssh root@sqlraqkey
Welcome to Ubuntu 12.10 (GNU/Linux 3.5.0-17-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of WedSep 24 18:32:03 EDT 2014
System load: 0.0 Users logged in: 1
Usage of /: 11.1% of 28.31GB IP address for eth0: 10.239.131.210
Memory usage: 26% IP address for eth1:192.168.222.4
Swap usage: 0% IP address for eth2:192.168.111.4
Processes: 73
Graph this data and managethis system at https://landscape.canonical.com/
*** System restart required ***
Last login: Wed Sep 24 18:15:40 2014 from yourong.sh.intel.com
root@sqlrabkey:~#