转载

Jenkins进阶系列之——09配置Linux系统ssh免密码登陆

ssh认证的完整描述:https://www.ibm.com/developerworks/cn/linux/security/openssh/part1/

说明:点我去查看

今天我们只说生成ssh的key,从而达到免密码登陆的目的。

不知道ssh是什么的自己看说明。好了,不废话了。

系统:CentOS 5.8

  1. 确认用户

     确认当前用户是你需要的用户!

    $ whoami froad    #froad用户,根据你自己的需求选择用户。我这儿用froad用户演示。

     

  2. 生成key
    $ 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文件中即可
  3. 配置

     将authorized_keys文件拷贝到需要被管理的电脑上。注意:放在用户目录下.ssh文件夹中。Linux用户会限制你的访问权限

     

  4.  验证

  5. $ 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的电脑,如果你想两台电脑互相访问均免密码。那么你还需要重复上面的步骤(机器的配置刚好相反)。

     

  6. 其他

   如果添加指纹的时候提示添加失败,是因为你以前添加过了这个ip的指纹。

   解决办法:将.ssh目录的known_hosts文件删除掉(好粗暴啊( ⊙ o ⊙ )啊!),也可以打开这个文件把对于ip的那条记录删除(这个就精细多了O(∩_∩)O哈哈~)

   如果操作步骤都正确,但是依然要求输入密码。一般是因为权限的问题。命令如下

chmod 644 ~/.ssh/authorized_keys

 

 有问题下面留言!

 

 

 

 

 

 

 

 

正文到此结束
Loading...