【转】使用ssh-copy-id 快速的配置免密登录
1、在需要免密登录其他机器的主机上 生成公钥,私钥等。
ssh-keygen -t rsa 回车回车回车
哪个用户登录就在哪个用户目录的.ssh目录下生成。
2、将以下命令做成脚本,因为环境不能下载,直接将ssh-copy-id 命令的脚本copy了。(创建ssh-copy-id.sh文件,将下面命令添加上去)
#!/bin/sh # Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work. ID_FILE="${HOME}/.ssh/id_rsa.pub" if [ "-i" = "$1" ]; then
shift
# check if we have parameters left, if so the first is the new ID file
if [ -n "$2" ]; then
if expr "$1" : ".*\.pub" > /dev/null ; then
ID_FILE="$1"
else
ID_FILE="$1.pub"
fi
shift # and this should leave $ as the target name
fi
else
if [ x$SSH_AUTH_SOCK != x ] ; then
GET_ID="$GET_ID ssh-add -L"
fi
fi if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
GET_ID="cat ${ID_FILE}"
fi if [ -z "`eval $GET_ID`" ]; then
echo "$0: ERROR: No identities found" >&
exit
fi if [ "$#" -lt ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 [-i [identity_file]] [user@]machine" >&
exit
fi { eval "$GET_ID" ; } | ssh $ "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys && (test -x /sbin/restorecon && /sbin/restorecon ~/.ssh ~/.ssh/authorized_keys >/dev/null 2>&1 || true)" || exit cat <<EOF
Now try logging into the machine, with "ssh '$1'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. EOF
3、使用做的脚本执行以下命令即可。
./ssh-copy-id.sh -i ~/.ssh/id_rsa.pub imcd@10.131.117.144
4、测试 ssh imcd@10.131.117.144 OK
5、配置hosts 设置别名。
转自: https://segmentfault.com/a/1190000012862011?utm_source=tag-newest
【转】使用ssh-copy-id 快速的配置免密登录的更多相关文章
- [Kubernetes]集群配置免密登录Permission denied (publickey,password) 解决办法
在用ansible部署Kubernetes集群是需要配置免密登录,但是遇到Permission denied (publickey,password)的问题 首先推断可能是sshd_config的配置 ...
- SSH配置免密登录
[参考文章]:linux服务器ssh免密码登录 [参考文章]:ssh分发秘钥时出现错误“Permission denied (publickey,gssapi-keyex,gssapi-with-mi ...
- centos配置免密登录
一.准备工作 1.先准备两台centos机器.例如:192.168.1.100和192.168.1.101两台机器,配置101免密登录100 2.默认centos会自带ssh和stfp,机器未安装,请 ...
- linux 服务器之间配置免密登录
客户机:172.16.1.2 远程机:172.16.1.3 1.远程机 a.允许root用户通过22端口登录 vi /etc/ssh/sshd_config PORT 22 PermitRootLog ...
- linux配置免密登录
例如: $ ssh -i ~/ec2.pem ubuntu@12.34.56.78 首先确定你可以以密码的形式连接远程服务器,也可以创建一个非超级管理员用户,并增加 sudo 权限. $ sudo s ...
- Linux下配置免密登录!
ssh-keygen 产生公钥与私钥对. ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ss ...
- CentOS配置SSH免密登录
假如我们有两台CentOS机器,192.168.199.101,192.168.199.102,要想在101上远程连接102可以通过ssh命令来实现 ssh 192.168.199.102 如果没有配 ...
- CentOS 配置远程主机ssh免密登录
ssh针对的是用户不是机器,同一机器不同用户需要单独配置ssh,才能实现该用户的免密登录 cd ~ cd ./.ssh 在./ssh目录下生成公钥与私钥(如果没有.ssh先使用ssh命令连接到一台远程 ...
- 大数据高可用集群环境安装与配置(03)——设置SSH免密登录
Hadoop的NameNode需要启动集群中所有机器的Hadoop守护进程,这个过程需要通过SSH登录来实现 Hadoop并没有提供SSH输入密码登录的形式,因此,为了能够顺利登录每台机器,需要将所有 ...
随机推荐
- 当async: true 时,ajax请求是异步的
方法beforeSend,用于在向服务器发送请求前添加一些处理函数. type:"GET",//通常会用到两种:GET,POST.默认是:GET url:" ...
- Mac下好玩的终端命令
figlet brew install figlet cowsay brew install cowsaycowsay -l: 查看所有可用动物cowsay -f daemon hello world ...
- java反序列化-ysoserial-调试分析总结篇(2)
前言: 这篇主要分析commonCollections2,调用链如下图所示: 调用链分析: 分析环境:jdk1.8.0 反序列化的入口点为src.zip!/java/util/PriorityQueu ...
- alibaba开发手册
alibaba开发手册 11.19 强制: 方法参数在定义和传入时,多个参数逗号后边必须加空格. IDE 的 text file encoding 设置为 UTF-8; IDE 中文件的换行符使用 ...
- 零基础JavaScript编码(三)总结
任务目的 在上一任务基础上继续JavaScript的体验 接触一下JavaScript中的高级选择器 学习JavaScript中的数组对象遍历.读写.排序等操作 学习简单的字符串处理操作 任务描述 参 ...
- 前端开发: webStorm手机真机调试
目录 1. 做好准备工作 2. 开始设置 3. 配置路径 4. 匹配路径设置 5. 设置完成,即可体验 文章首发微信公众号飙码人生 2018-05-21 18:21:15 1. 做好准备工作 安装we ...
- 数据结构-ST表
数据结构-ST表 不可修改,在线查询的 RMQ 问题. 其中 \(f[i][j]\) 表示 \(i\sim i+(1<<j)-1\) 这段的 RMQ 值. 时间复杂度 \(O(n\log ...
- vue开发路由相关基础知识和笔记
路由实现:hash模式 和 history模式 hash模式: 概述 在浏览器中符号"#",#以及#后面的字符称之为hash,用window.location.hash读取: 特点 ...
- 关于gradle与maven对springboot项目的配置文件加载异同
先说下缘由吧,由于年后跳槽换了家公司,构建项目工具也有maven改成gradle了,所以在搭建框架进行开发打包过程中难免会遇到一些意想不到的问题. 本文简述下打包扫描加载配置文件的异同吧. maven ...
- 数据库--Redis
原因: 源码是官方configure过的,但官方configure时,生成的文件有时间戳信息,所以如果你的虚拟机的时间不对,比如说是2022年,就可能会出错 解决: date -s ‘yyyy-mm- ...