您的位置:首页 > 其它

Ubuntu 下 SSH 实现远程登录 无需输入密码

2014-09-04 16:25 676 查看
首先准备两台linux OS 的机子,这里用的是虚拟机

第一台:

chiwei@chiwei-VirtualBox:~$ hostname

chiwei-VirtualBox

IP:192.168.8.144

第二台:

chiwei@chiwei-hadoop:~/.ssh$ hostname

chiwei-hadoop

IP:192.168.8.200

分别在两台机子上安装openssh-server     http://blog.csdn.net/simonchi/article/details/38871953    这里有说明

安装完成之后就可以使用SSH命令了

在第一台执行  ssh-keygen -t rsa   

chiwei@chiwei-VirtualBox:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/chiwei/.ssh/id_rsa): 

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/chiwei/.ssh/id_rsa.

Your public key has been saved in /home/chiwei/.ssh/id_rsa.pub.

The key fingerprint is:

1d:45:b5:a3:54:6e:a7:f6:65:79:27:9b:a6:1c:d4:d2 chiwei@chiwei-VirtualBox

The key's randomart image is:

+--[ RSA 2048]----+

|           .o.o  |

|           . o . |

|          . . = .|

|         . o = +.|

|        S . + E.=|

|           . o *+|

|            . + .|

|           . +   |

|            o    |

+-----------------+

执行   cp id_rsa.pub authorized_keys

执行

chiwei@chiwei-VirtualBox:~/.ssh$ scp authorized_keys chiwei@chiwei-hadoop:/home/chiwei/.ssh

chiwei@chiwei-hadoop's password: 

authorized_keys                                                                                                                                                            100%  406     0.4KB/s   00:00    

chiwei@chiwei-VirtualBox:~/.ssh$ ssh chiwei-hadoop

Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

359 packages can be updated.

6 updates are security updates.

到第二台机子去查看

chiwei@chiwei-hadoop:~/.ssh$ ls

authorized_keys  id_rsa  id_rsa.pub

chiwei@chiwei-hadoop:~/.ssh$ 

已经文件传过来了

现在在第一台机子直接ssh   第二台主机  就可以直接登录了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: