ssh认证的完整描述:https://www.ibm.com/developerworks/cn/linux/security/openssh/part1/html
说明:点我去查看linux
今天咱们只说生成ssh的key,从而达到免密码登录的目的。dom
不知道ssh是什么的本身看说明。好了,不废话了。ssh
系统:CentOS 5.8ide
确认当前用户是你须要的用户!加密
$ whoami froad #froad用户,根据你本身的需求选择用户。我这儿用froad用户演示。
$ cd ~ #回到用户目录,不回去也没有关系 $ ssh-keygen #可使用-t选项选择加密方式,包括 RSA 和 DSA 两种密钥 #例如:$ssh-keygen -t dsa 或者ssh-keygen -t rsa #加密方式不一样,key的名称不一样,其余没有区别 #若是没有指定密钥,默认RSA Generating public/private rsa key pair. Enter file in which to save the key (/home/froad/.ssh/id_rsa): #私钥存放的位置,默认会存放在用户目录的.ssh文件夹,直接回车 Enter passphrase (empty for no passphrase): #默认,回车 Enter same passphrase again: #默认,回车 Your identification has been saved in /home/froad/.ssh/id_rsa.#私钥路径 Your public key has been saved in /home/froad/.ssh/id_rsa.pub.#公钥路径 The key fingerprint is: e8:b6:e6:xxxxxxxxxxxxxxxxx:ec:b5:d8 froad@localhost.localdomain $ cat id_***.pub >> authorized_keys #***表明加密方式,将公钥拷贝到authorized_keys文件中。若是你有不少的电脑须要配置,将全部的id_***.pub公钥拷贝到一个authorized_keys文件中便可
将authorized_keys文件拷贝到须要被管理的电脑上。注意:放在用户目录下.ssh文件夹中。Linux用户会限制你的访问权限spa
验证code
$ ssh root@192.168.2.xxx #root是用户名,能够根据你的需求改变 The authenticity of host '192.168.2.xxx (192.168.2.xxx)' can't be established. RSA key fingerprint is ff:07:49:4d:xxxxxxxxxxe:2c:38. Are you sure you want to continue connecting (yes/no)? yes #赞成将指纹添加到本地 Warning: Permanently added '192.168.2.xxx' (RSA) to the list of known hosts. Last login: Wed Oct 23 13:58:32 2013 from 192.168.1.xxx
只能在你生成key的电脑上访问authorized_keys的电脑,若是你想两台电脑互相访问均免密码。那么你还须要重复上面的步骤(机器的配置恰好相反)。htm
若是添加指纹的时候提示添加失败,是由于你之前添加过了这个ip的指纹。blog
解决办法:将.ssh目录的known_hosts文件删除掉(好粗暴啊( ⊙ o ⊙ )啊!),也能够打开这个文件把对于ip的那条记录删除(这个就精细多了O(∩_∩)O哈哈~)
若是操做步骤都正确,可是依然要求输入密码。通常是由于权限的问题。命令以下
chmod 644 ~/.ssh/authorized_keys
转:http://www.cnblogs.com/zz0412/p/jenkins_jj_09.html 点击打开连接