【转】使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录
第一步:在本地机器上使用ssh-keygen产生公钥私钥对
jsmith@local-host$ [Note: You are on local-host here]
jsmith@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host
第二步:用ssh-copy-id将公钥复制到远程机器中
jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中
第三步: 登录到远程机器不用输入密码
jsmith@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]
jsmith@remote-host$ [Note: You are on remote-host here]
常见问题:
- ssh-copy-id -u eucalyptus -i ~eucalyptus/.ssh/id_rsa.pub eucalyptus@remote_host
上述是给eucalyptus用户赋予无密码登陆的权利
[1]
/usr/bin/ssh-copy-id: ERROR: No identities found
使用选项 -i ,当没有值传递的时候或者 如果 ~/.ssh/identity.pub 文件不可访问(不存在), ssh-copy-id 将显示上述的错误信息 ( -i选项会优先使用将ssh-add -L的内容)
jsmith@local-host$ ssh-agent $SHELL
jsmith@local-host$ ssh-add -L
The agent has no identities.
jsmith@local-host$ ssh-add
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)
jsmith@local-host$ ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV
aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa
jsmith@local-host$ ssh-copy-id -i remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[Note: This has added the key displayed by ssh-add -L]
[2] ssh-copy-id应注意的三个小地方
- 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. - 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. - 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.
- 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).
【转】使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录的更多相关文章
- 使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录
ssh-keygen 产生公钥与私钥对. ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ss ...
- 【转载】ssh-copy-id三步实现SSH无密码登录和ssh常用命令
ssh-keygen 产生公钥与私钥对 ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./s ...
- ssh-copy-id三步实现SSH无密码登录和ssh常用命令
第一步:在本地机器上使用ssh-keygen产生公钥私钥对 $ ssh-keygen 第二步:用ssh-copy-id将公钥复制到远程机器中 $ ssh-copy-id -i .ssh/id_rsa ...
- ssh-copy-id三步实现SSH免密登录
背景 在日常工作中,不希望每次登录都输入密码,这里主要介绍一种简单的配置Linux主机间免密登录的方式 先了解两个核心命令: ssh-keygen :产生公钥和私钥对 ssh-copy-id:将北极的 ...
- 【Linux】ssh-copy-id三步实现ssh免密登陆
一.本地机器上使用ssh-keygen产生公钥私钥对 ssh-keygen -t rsa -C "XXXX@163.com" --->执行完会在~/.ssh/下生成公钥私钥对 ...
- 批量SSH key-gen无密码登陆认证脚本
SSH key-gen无密码登录认证脚本 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 通过 ssh-key-gen 来 ...
- 批量SSH key-gen无密码登陆认证脚本 附件脚本
# 批量实现SSH无密码登陆认证脚本 ## 问题背景 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 1.通过 ssh-k ...
- ssh无密码登录设置
为啥要设置ssh无密码登录? 我们先来看一下分布式系统的一键启动流程, 在matser机器上运行脚本,脚本检测有多少slavers,然后通过ssh登录到slavers,进入到相同的目录(或者通过$XX ...
- 批量实现多台服务器之间ssh无密码登录的相互信任关系
最近IDC上架了一批hadoop大数据业务服务器,由于集群环境需要在这些服务器之间实现ssh无密码登录的相互信任关系.具体的实现思路:在其中的任一台服务器上通过"ssh-keygen -t ...
随机推荐
- .Net MVC Redirect出现:服务器无法在已发送 HTTP 标头之后设置状态解决方案
使用过滤器控制权限时,若无权则跳转到无权页面,但是每次跳转都会出现 ERROR - System.Web.HttpException (0x80004005): 服务器无法在已发送 HTTP 标头之后 ...
- Autofac官方文档翻译--一、注册组件--1注册概念
官方文档:http://docs.autofac.org/en/latest/register/registration.html 一.注册概念 使用Autofac 注册组件,通过创建一个Contai ...
- (三)文件的链接(ln)
一.链接的分类及特点 当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link ...
- 创建txt文件,并且写入内容
使用fopen的w方式就可以创建一个新的txt文件,如果文件名存在该文件内容会消失. 1. fopen的函数原型:FILE * fopen(const char * path,const char * ...
- JS实现JSON数组合并和去重
var a=[{"id":"1001","name":"张三","age":"18&quo ...
- Oracle数据库常见sql
-新建表:create table table_name( id varchar2(300) primary key, name varchar2(200) not null); --插入数据 ins ...
- [LeetCode]654. Maximum Binary Tree最大堆二叉树
每次找到数组中的最大值,然后递归的构建左右树 public TreeNode constructMaximumBinaryTree(int[] nums) { if (nums.length==0) ...
- 使用UML工具分析类图与类的关系-bouml(java和C++)
在分析类之间的关系时可以借助工具来实现. bouml是一个UML分析工具,最新的版本是收费的,但是之前的版本是免费的. 这里使用的是4.23版. Bouml安装: 安装软件就按照流程走就行了.但是第一 ...
- 基于E-PUCK 2.0多智能体自主协同 高频投影定位系统
群体智能机器人是一种国际前沿的人工智能研究项目,由多个小型机器人组成的集群式解决系统,灵感源于蚂蚁.蜜蜂.鱼等群体生物,在没有统一领导的情况下,也能合作执行大量复杂的任务,比如组建一个图形,再在此基础 ...
- 记录一次 Nginx 配置 proxy_pass 后 返回404问题
一. Nginx 配置 proxy_pass 后 返回404问题 故障解决和定位 1.1. 问题 在一次生产涉及多次转发的配置中, 需求是下面的图: 在配置好了 proxy_pass 之后,请求 ww ...