当前位置:网站首页>##脚本编写ssh免密功能
##脚本编写ssh免密功能
2022-06-25 12:39:00 【51CTO】
生产中,部署集群时,我们离不开机器与机器间的免密操作,所以我们用脚本来实现,减少时间。
#!/bin/bash
#实现自动化免密登录
read -p "请输入被控制虚拟机的IP:" ip
echo "$ip"
read -p "请输入被控制虚拟机的账号:" user
echo "$user"
read -p "请输入被控制虚拟机的端口号:" port
echo "$port"
if [ -z "$port" ]
then
Port=22
fi
read -p "生成对应的key(y/n):" key
echo "$key"
if [ "y" = "key" ]
then
echo "需要生成公钥私钥,请连续敲击三次回车~"
#3次回车后,在本地生成公钥私钥
ssh-keygen -t rsa
fi
echo "创建正在被控制虚拟机的文件夹.sh,输入被控制虚拟机的密码...."
scp -p "$port $user $ip "mkdir /root/server/ssh/.ssh ; chmod 0700 /root/server/ssh/.ssh""
echo "正在传输公钥和私钥,请输入被控制虚拟机的密码"
scp -P $port ~/.shh/id_rsa.pub [email protected]$ip:.ssh/id_rsa.pub
echo "正在生成免密登录,请输入被控制虚拟机的密码"
ssh -p $port $user $ip
if [ ! -f ~/.ssh/authorized_keys ]
then
touch ~/.ssh/authorized_keys
fi
chmod 600 ~/.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
echo "恭喜您成功配置完成免密登录!!!请尝试登录..."
echo "ssh -p $port $user $ip"
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
边栏推荐
- 关于数据在内存中的存储下
- 坡道带来的困惑
- 原生js---无限滚动
- Fedora 35 deploys DNS master-slave and separation resolution -- the way to build a dream
- Summary of leetcode linked list problem solving skills
- WIN10环境下配置pytorch
- Some knowledge about structure, enumeration and union
- 一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
- 提高排名的 15 个基本 SEO 技巧
- Component: is to switch between multiple components
猜你喜欢

深圳民太安智能二面_秋招第一份offer

Maui's learning path (II) -- setting

Optimization of lazyagg query rewriting in parsing data warehouse

數據在內存中的存儲相關內容

leetcode - 384. 打乱数组

關於一道教材題的講解

Sword finger offer day 2 linked list (simple)

leetcode:剑指 Offer II 091. 粉刷房子【二维dp】

Uncover gaussdb (for redis): comprehensive comparison of CODIS
![[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer](/img/77/715454c8203d722e246ed70e1fe0d8.png)
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
随机推荐
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box
.NET in China - What's New in .NET
剑指 Offer II 032. 有效的变位词
关于一道教材题的讲解
Golang keyboard input statement scanln scanf code example
汇编标志位相关知识点(连)
Using swiper to realize seamless rotation of multiple slides
几分钟上线一个网站 真是神器
Detailed explanation of string operation functions and memory functions
Alibaba stability fault emergency handling process
[转]以终为始,详细分析高考志愿该怎么填
量化交易之回测篇 - 期货CTA策略策略(TQZFutureRenkoWaveStrategy)
Custom vertical table
Introduction to mongodb chapter 01 introduction to mongodb
[pit avoidance refers to "difficult"] antd cascader implements new customized functions
关于结构体,枚举,联合的一些知识
初始c语言时的一些知识
Sword finger offer day 3 string (simple)
Stockage des données en mémoire
剑指 Offer 04. 二维数组中的查找