假设服务器IP地址为192.168.1.1,机器名:cluster.hpc.org
客户端IP地址为172.16.16.1,机器名:p470-2.wangrx.sioc.ac.cn
客户端用户yzhao需要使用ssh无密码登录服务器的zhaoy帐户
实现原理
使用一种被称为"公私钥"认证的方式来进行ssh登录. "公私钥"认证方式简单的解释是
首先在客户端上创建一对公私钥 (公钥文件:~/.ssh/id_rsa.pub; 私钥文件:~/.ssh/id_rsa)
然后把公钥放到服务器上(~/.ssh/authorized_keys), 自己保留好私钥
当ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配.如果匹配成功就可以登录了
设置如下:
1、以yzhao用户登录客户机器并在客户端机器上执行"ssh-keygen -t rsa"
(注:每次执行"ssh-keygen -t rsa"产生的私钥文件都会不同)
a)如果文件"~/.ssh/id_rsa"存在,会提示是否覆盖该文件,此时可选择"n"不覆盖该文件而使用已有的id_rsa文件;如果选择"y"则会重新生成"~/.ssh/id_rsa"文件,接下来会提示输入passphrase,回车确定使用空的passphrase,再次回车确认(这里也可以输出passphrase,相当于ssh时登录的密码)。然后会重新生成"~/.ssh/id_rsa"文件和"~/.ssh/id_rsa.pub"文件(结果如下)。
[yzhao@p470-2 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/disk2/yzhao/.ssh/id_rsa):
/disk2/yzhao/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /disk2/yzhao/.ssh/id_rsa.
Your public key has been saved in /disk2/yzhao/.ssh/id_rsa.pub.
The key fingerprint is:
6d:a1:17:8a:b6:d2:c0:a1:6c:66:ba:85:0b:7b:9f:0c yzhao@p470-2.wangrx.sioc.ac.cn
b)如果"~/.ssh/id_rsa"文件和"~/.ssh/id_rsa.pub"文件不存在则会自动创建新的"~/.ssh/id_rsa"文件和"~/.ssh/id_rsa.pub"文件,passphrase设置同上。
[yzhao@p470-2 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/disk2/yzhao/.ssh/id_rsa):
Created directory '/disk2/yzhao/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /disk2/yzhao/.ssh/id_rsa.
Your public key has been saved in /disk2/yzhao/.ssh/id_rsa.pub.
The key fingerprint is:
54:49:ad:33:b3:ff:71:da:6d:db:78:d0:bb:6a:15:bc yzhao@p470-2.wangrx.sioc.ac.cn
2、使用ssh zhaoy@192.168.1.1登录到服务器,编辑服务器上"~/.ssh/authorized_keys"文件,将客户端机器上的"~/.ssh/id_rsa.pub"文件内容追加到"~/.ssh/authorized_keys"文件中。
(注:可以在客户端机器上使用以下命令来实现:
cat ~/.ssh/id_rsa.pub | ssh zhaoy@192.168.1.1 "cat - >> ~/.ssh/authorized_keys"
此时会要求输入zhaoy在服务器上的登录密码,输入后即会将客户端机器上的"~/.ssh/id_rsa.pub"文件内容追加到服务器上的"~/.ssh/authorized_keys"文件中)
如果是首次连接服务器会出现以下的提示,确认连接并输入密码后其他直接回车确定。
[yzhao@p470-2 ~]$ ssh zhaoy@192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is 94:91:33:01:6b:e7:10:ae:42:ac:ea:5c:8c:bb:f1:18.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
zhaoy@192.168.1.1's password:
Last login: Fri Dec 21 17:41:38 2007 from 172.16.16.1
Rocks 4.2.1 (Cydonia)
Profile built 03:58 21-Jun-2007
Kickstarted 12:25 21-Jun-2007
Rocks Frontend Node - Our Cluster Cluster
It doesn't appear that you have set up your ssh key.
This process will make the files:
/home/zhaoy/.ssh/id_rsa.pub
/home/zhaoy/.ssh/id_rsa
/home/zhaoy/.ssh/authorized_keys
Generating public/private rsa key pair.
Enter file in which to save the key (/home/zhaoy/.ssh/id_rsa):
Created directory '/home/zhaoy/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/zhaoy/.ssh/id_rsa.
Your public key has been saved in /home/zhaoy/.ssh/id_rsa.pub.
The key fingerprint is:
7e:f6:ab:b0:79:70:cb:c9:f7:40:37:aa:10:4d:4a:ac zhaoy@cluster.hpc.org
3、如果在第1步中使用了空的passphrase,则可以跳过第4步,此时在客户端即可以使用"ssh zhaoy@192.168.1.1"即可无密码登录到服务器;如果第一步中设置了passphrase,则继续执行以下步骤。
4、如果第1步中设置了passphrase,则此时需要输入该passphrase登录服务器。此时前面我们把输入密码变成了输入passphrase,这没有带来任何方便。但是我们可以通过ssh-agent来帮助我们自动输入passphrase(只是看起来像是自动输入而已),我们只要在第一次登录时输入一次passphrase, 以后的工作就可以交给ssh-agent。在客户端机器上执行命令ssh-add,这里会提示输入一次passphrase。输入第一步中设置的passphrase之后会修改"~/.ssh/id_rsa"文件。再在客户端执行"ssh zhaoy@192.168.1.1"即可无密码登录到服务器端。
[yzhao@p470-2 ~]$ ssh-add
Enter passphrase for /disk2/yzhao/.ssh/id_rsa:
Identity added: /disk2/yzhao/.ssh/id_rsa (/disk2/yzhao/.ssh/id_rsa)
[yzhao@p470-2 ~]$ ssh zhaoy@192.168.1.1
Last login: Fri Dec 21 17:55:38 2007 from 172.16.16.1
Rocks 4.2.1 (Cydonia)
Profile built 03:58 21-Jun-2007
Kickstarted 12:25 21-Jun-2007
Rocks Frontend Node - Our Cluster Cluster
[zhaoy@cluster ~]$
分享到:
相关推荐
ssh登录使用radius服务器认证配置方法
配置linux ssh免密码登录,第一行生成密钥,第二行是要对哪台机器免密码ssh登录就配置成哪一台,这里root@hadoop00,root是用户名,hadoop00是主机名
SSH密钥方式登录Linux,SSH密钥方式登录Linux
Linux环境通过shell脚本进行ssh登录服务器 里面包好ssh登录的用法以及interact交互 以及通过echo覆盖文件或者重定向文本,输入ssh远程服务器的密码,账户完全自动输入账号,密码登录服务器
ssh工具 用于连接远程服务器 linux 系统 解压 安装即可使用
LINUX中RSA认证登录SSH.docx
嵌入式Linux SSH服务搭建 编译好的ssh 目录/Source/openssh-4.6p1为编译后的文件 版本:openssh-4.6p1、openssl-0.9.8f、zlib-1.2.3
ssh登录到对方的机器而不需要密码,非常实用,特别是zookeeper,hadoop 教程也非常清晰,简单
Linux配置ssh免密码登录调试文档,对配置hadoop有帮助
1. 打开左上角session 3. 输入远程服务器地址和用户名 4. 打开Advanced SSH settings输入本地私钥文件地址
使用一种被称为”公私钥”认证的方式来进行ssh登录。”公私钥”认证方式简单的解释是: 首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_rsa.pub;私钥文件:~/.ssh/id_rsa),然后把公钥放到服务器上(~/.ssh/...
PuTTY是一个Telnet、SSH、rlogin、纯TCP...随着Linux在服务器端应用的普及,Linux系统管理越来越依赖于远程。在各种远程登录工具中,Putty是出色的工具之一。Putty是一个免费的、Windows x86平台下的Telnet、SSH和rlo
linux下怎样设置ssh无密码登录.docx
java实现ssh方式连接linux(包含ganymed-ssh2-build210.jar包) ---------Java语言+绚丽的界面+仿ssh实现调用Linux的Terminal,实现远程连接linux进行命令行的操作!
登录linux服务器ssh软件
linux系统下的ssh免密码登录机制原理及范例
连接Linux服务器工具SSH 3.2.9 方便快捷!
1 什么是SSH ...为了在不同平台/网络主机之间的通信安全, 很多时候我们都要通过ssh进行认证. ssh认证方式主要有2种: ① 基于口令的安全认证: 每次登录的时候都要输入用户名和密码, 由于要在网络上传输密码,
Linux_SSH配置和禁止Root远程登陆设置文档