当前位置:网站首页>##脚本编写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.
边栏推荐
- WIN10环境下配置pytorch
- 学习编程的起点。
- Maui's learning path (II) -- setting
- There is a problem with the date when MySQL imports and exports data to excel
- 量化交易之回测篇 - 期货CTA策略策略(TQZFutureRenkoWaveStrategy)
- [pit avoidance refers to "difficult"] antd cascader implements new customized functions
- [pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
- Summer Ending
- Germany holds global food security Solidarity Conference
- Component: is to switch between multiple components
猜你喜欢
leetcode - 384. Scramble array
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
关于数据在内存中的存储下
OpenStack学习笔记(一)
Serenvlt first met
Summer Ending
關於一道教材題的講解
數據在內存中的存儲相關內容
leetcode:456. 132 mode [monotone stack]
Uncover gaussdb (for redis): comprehensive comparison of CODIS
随机推荐
初始c语言的知识2.0
Seven competencies required by architects
Confusion caused by the ramp
Sword finger offer II 032 Effective anagrams
Qt鼠标跟踪
[data visualization] antv L7 realizes map visualization, drilldownlayer drill asynchronously obtains data, and suspends the warning box
golang键盘输入语句scanln scanf代码示例
关于一道教材题的讲解
量化交易之回测篇 - 期货CTA策略实例(TQZFutureRenkoScalpingStrategy)
中国虚拟人哪家强?沙利文、IDC:小冰百度商汤位列第一梯队
[turn] starting from the end, analyze in detail how to fill in the college entrance examination volunteer
數據在內存中的存儲相關內容
剑指 Offer II 028. 展平多级双向链表
坡道带来的困惑
Summer Ending
Where is it safe to open an account for buying funds? Please give me your advice
Openstack learning notes -nova component insight
Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
Openstack -- creating virtual machines for Nova source code analysis
Drago Education - typescript learning