ssh-keygen  产生公钥与私钥对.
ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ssh , 和 ~/.ssh/authorized_keys的权利
第一步:在本地机器上使用ssh-keygen产生公钥私钥对

  1. jsmith@local-host$ [Note: You are on local-host here]
  2. jsmith@local-host$ ssh-keygen
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
  5. Enter passphrase (empty for no passphrase): [Press enter key]
  6. Enter same passphrase again: [Pess enter key]
  7. Your identification has been saved in /home/jsmith/.ssh/id_rsa.
  8. Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
  9. The key fingerprint is:
  10. 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host

第二步:用ssh-copy-id将公钥复制到远程机器中

  1. jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
  2. jsmith@remote-host's password:
  3. Now try logging into the machine, with "ssh 'remote-host'", and check in:
  4. .ssh/authorized_keys
  5. to make sure we haven't added extra keys that you weren't expecting.

注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中

第三步: 登录到远程机器不用输入密码

  1. jsmith@local-host$ ssh remote-host
  2. Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
  3. [Note: SSH did not ask for password.]
  4. jsmith@remote-host$ [Note: You are on remote-host here]

常见问题:

  1. ssh-copy-id -u eucalyptus -i ~eucalyptus/.ssh/id_rsa.pub eucalyptus@remote_host

上述是给eucalyptus用户赋予无密码登陆的权利

[1]

  1. /usr/bin/ssh-copy-id: ERROR: No identities found

使用选项 -i ,当没有值传递的时候或者 如果 ~/.ssh/identity.pub 文件不可访问(不存在), ssh-copy-id 将显示上述的错误信息  ( -i选项会优先使用将ssh-add -L的内容)

  1. jsmith@local-host$ ssh-agent $SHELL
  2. jsmith@local-host$ ssh-add -L
  3. The agent has no identities.
  4. jsmith@local-host$ ssh-add
  5. Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)
  6. jsmith@local-host$ ssh-add -L
  7. ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV
  8. aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa
  9. jsmith@local-host$ ssh-copy-id -i remote-host
  10. jsmith@remote-host's password:
  11. Now try logging into the machine, with "ssh 'remote-host'", and check in:
  12. .ssh/authorized_keys
  13. to make sure we haven't added extra keys that you weren't expecting.
  14. [Note: This has added the key displayed by ssh-add -L]

[2] ssh-copy-id应注意的三个小地方

  1. Default public key: ssh-copy-id uses ~/.ssh/identity.pub as the default public key file (i.e when no value is passed to option -i). Instead, I wish it uses id_dsa.pub, or id_rsa.pub, or identity.pub as default keys. i.e If any one of them exist, it should copy that to the remote-host. If two or three of them exist, it should copy identity.pub as default.
  2. The agent has no identities: When the ssh-agent is running and the ssh-add -L returns “The agent has no identities” (i.e no keys are added to the ssh-agent), the ssh-copy-id will still copy the message “The agent has no identities” to the remote-host’s authorized_keys entry.
  3. Duplicate entry in authorized_keys: I wish ssh-copy-id validates duplicate entry on the remote-host’s authorized_keys. If you execute ssh-copy-id multiple times on the local-host, it will keep appending the same key on the remote-host’s authorized_keys file without checking for duplicates. Even with duplicate entries everything works as expected. But, I would like to have my authorized_keys file clutter free.

使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录的更多相关文章

  1. 【转】使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录

    [原]http://blog.chinaunix.net/uid-26284395-id-2949145.html ssh-keygen  产生公钥与私钥对. ssh-copy-id 将本机的公钥复制 ...

  2. 【转载】ssh-copy-id三步实现SSH无密码登录和ssh常用命令

      ssh-keygen  产生公钥与私钥对 ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./s ...

  3. ssh-copy-id三步实现SSH无密码登录和ssh常用命令

    第一步:在本地机器上使用ssh-keygen产生公钥私钥对 $ ssh-keygen 第二步:用ssh-copy-id将公钥复制到远程机器中 $  ssh-copy-id -i .ssh/id_rsa ...

  4. ssh-copy-id三步实现SSH免密登录

    背景 在日常工作中,不希望每次登录都输入密码,这里主要介绍一种简单的配置Linux主机间免密登录的方式 先了解两个核心命令: ssh-keygen :产生公钥和私钥对 ssh-copy-id:将北极的 ...

  5. 【Linux】ssh-copy-id三步实现ssh免密登陆

    一.本地机器上使用ssh-keygen产生公钥私钥对 ssh-keygen -t rsa -C "XXXX@163.com" --->执行完会在~/.ssh/下生成公钥私钥对 ...

  6. 批量SSH key-gen无密码登陆认证脚本

    SSH key-gen无密码登录认证脚本 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 通过 ssh-key-gen 来 ...

  7. 批量SSH key-gen无密码登陆认证脚本 附件脚本

    # 批量实现SSH无密码登陆认证脚本 ## 问题背景 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 1.通过 ssh-k ...

  8. SSH的三个组件ssh、sftp、scp介绍

    SSH  包含3个组件 (1) ssh 远程登录节点 : ssh 用户名@IP地址 ① 不允许空密码或错误密码认证登录 ② 不允许root用户登录 ③ 有两个版本 ssh,ssh2安全性更高 (2)  ...

  9. 批量实现多台服务器之间ssh无密码登录的相互信任关系

    最近IDC上架了一批hadoop大数据业务服务器,由于集群环境需要在这些服务器之间实现ssh无密码登录的相互信任关系.具体的实现思路:在其中的任一台服务器上通过"ssh-keygen -t ...

随机推荐

  1. java RSA 生成公钥私钥

    /** * 引进的包都是Java自带的jar包 * 秘钥相关包 * base64 编解码 * 这里只用到了编码 */ import java.security.Key; import java.sec ...

  2. testUrl

    def ConnectTest(url): try: response = requests.get(url) return response.status_code except requests. ...

  3. Node.js学习笔记(4)--简单路由,老师学生id

    说明(2017-5-2 17:57:23): 1. foo.js var http = require("http"); var url = require("url&q ...

  4. 电商网站jQuery放大镜代码

    分享一款电商网站jQuery放大镜代码.这是一款基于jquery.elevatezoom插件实现的类似淘宝放大镜代码,提供40多种参数,可自由配置多种效果,适合电商或图片类网站使用.效果图如下: 在线 ...

  5. 【转】 oracle 层次查询判断叶子和根节点

    Oracle 9i判断是叶子或根节点,是比较麻烦的一件事情,SQL演示脚本如下: DROP TABLE idb_hierarchical; create TABLE idb_hierarchical ...

  6. setOnPageChangeListener 过时了怎么办?

    今天使用ViewPager发现setOnPageChangeListener的方法竟然过期了.并且AS编译不通过了,最后查了一下原来把set换成add了,代码例如以下: setOnPageChange ...

  7. 建立window SVN服务器

    在windows下搭建SVN服务器: 首先从http://www.visualsvn.com/server/download/ 下载最新的VisualSVN-Server-x.x.x.msi,然后本机 ...

  8. python获取软件安装列表2222

    softer_installed_list ===================== 使用python编写的,获取本机软件安装列表,输出为html表格. * win7 32位环境下运行 * 使用的是 ...

  9. CentOS重置Mysql密码

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...

  10. winsock.h与winsock2.h出现重定义或不同的链接

    经常遇到编译socket程序的时候生成几百个错误 以下是出错后的错误信息: >c:\program files\microsoft sdks\windows\v6.0a\include\ws2d ...