当前位置:网站首页>Solving SCP command secret free login in shell script
Solving SCP command secret free login in shell script
2022-04-22 21:18:00 【Rookie zyy】
Application scenarios : Remote transfer of files between servers
Two Server password free login
Four cluster servers
| The server | IP |
|---|---|
| A | 47.110.129.242 |
| B | 172.16.214.209 |
| C | 172.16.214.251 |
| D | 172.16.214.252 |
Generate server public key and private key file
Host computer A Execute the following command to generate the pairing key (id_rsa,id_rsa.pub):
ssh-keygen -t rsa
During execution, you will stay and directly press enter to execute the result :

take A service /home/user_01/.ssh/id_rsa.pub Copy the public key file to B The service corresponds to .shh Directory and modify the file name authorized_keys
scp -P 22033 /home/user_01/.ssh/id_rsa.pub [email protected]:/home/user_01/.ssh/authorized_keys.pub
You need to enter the server password
C,D Service duplication B Service public key file replication , Refer to the instructions above
2 . Verify success
Repeat the above file scp The command does not require a password
Two edit shell Script
- Create a file transfer file scp.sh
touch scp.sh
- Edit the file
vim scp.sh
scp -r -P 22033 /wwwroot/java/config [email protected]:/wwwroot/java/
scp -r -P 22033 /wwwroot/java/config [email protected]:/wwwroot/java/
scp -r -P 22033 /wwwroot/java/config [email protected]:/wwwroot/java/
#scp -P 22033 /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/
#scp -P 22033 /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/
#scp -P 22033 /wwwroot/java/tomcat-app/kxgzapp.war [email protected]:/wwwroot/java/tomcat-app/
sleep 5
# Start the server
/wwwroot/java/restart-tomcat.sh app kxgzapp
ssh -p 22033 172.16.214.209
/wwwroot/java/restart-tomcat.sh app kxgzapp
exit
ssh -p 22033 172.16.214.251
/wwwroot/java/restart-tomcat.sh app kxgzapp
exit
ssh -p 22033 172.16.214.252
/wwwroot/java/restart-tomcat.sh app kxgzapp
exit
- Yes scp.sh Grant execution permission to the file
chmod 777 *.sh
- Finally, execute sh file
./scp.sh
6.tomcat Start backup
install unzip
yum install -y unzip zip
vim restart-tomcat.sh
#!/bin/bash
tomcat_path=/wwwroot/java/tomcat-${
1}
tomcat_name=tomcat-${
1}
config=/wwwroot/java/config/
war_name=${
2}
bak_path=/wwwroot/java/update/bg/
echo "begin get ${tomcat_name} pid"
tomcat8_id=$(ps -ef | grep ${
tomcat_name} | grep -v grep | awk '{print $2}')
echo "${tomcat_name} pid:$tomcat8_id"
echo "begin kill ${tomcat_name} pid:$tomcat8_id"
kill -9 $tomcat8_id
sleep 3
echo "kill ${tomcat_name} pid:$tomcat8_id,success"
mv ${
tomcat_path}/webapps/${
war_name}.war ${
bak_path}
rm -rf ${
tomcat_path}/webapps/${
war_name}
echo "remove war name ${war_name}"
mv /wwwroot/java/config/${
war_name}/war/*.war ${
tomcat_path}/webapps/${
war_name}.war
# decompression war package
unzip -oq ${
tomcat_path}/webapps/${
war_name}.war -d ${
tomcat_path}/webapps/${
war_name}
# Modify the configuration
cp -r /wwwroot/java/config/${
war_name}/config/* ${
tomcat_path}/webapps/${
war_name}/WEB-INF/classes
sleep 4
# start-up tomcat
${
tomcat_path}/bin/startup.sh
echo "runing tomcat ..."
tomcat8_id=$(ps -ef | grep ${
tomcat_name} | grep -v grep | awk '{print $2}')
echo "now ${tomcat_name} pid:$tomcat8_id"
sleep 4
tail -f ${
tomcat_path}/logs/catalina.out
Run script
./restart-tomcat.sh app kxgzapp
Just killing the process can use
$ ps -ef | grep pro_name | grep -v grep | awk '{print $2}' | xargs kill -15
版权声明
本文为[Rookie zyy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222115302936.html
边栏推荐
- 最新版去水印+外賣cps小程序源碼
- Big talk test data (II): acquisition of concept test data
- QT uses windeployqt Exe packaging program
- select distinct语句 去重
- 解数独[Pre-DS-hash结构 + component-DFS | Pre-hash-1-9特性--二进制状态压缩 + DFS]
- SH file content startup file
- Selenium_Webdriver视频自动化脚本分享
- C语言初阶最后一课:倒置字符串(例如:I like beijing.打印成:beijing.like I)
- 【数据清洗、绘图】Dataframe的简易应用
- Navicat for MySQL 连接 Docker中运行的Mysql出现1251- Client does not support authentication protocol 错误
猜你喜欢

2022-4-22 Leetcode 91. Decoding method

Use of dSPACE simulation platform

345 leetcode ransom letter

DSPACE simulates simple accident scene

QT uses windeployqt Exe packaging program

Soochow securities x kangaroo cloud: the data is easily available and has millisecond response ability. What did Soochow securities do right?

M5增强版双系统套餐包含哪些重要配件,该怎么选?
![[hand pose estimation] [detailed reading of the paper] 3D hand pose estimation with a single infrared camera via domain transfer learning](/img/78/945806131ee10afe7db777bf7eb5fe.png)
[hand pose estimation] [detailed reading of the paper] 3D hand pose estimation with a single infrared camera via domain transfer learning

Big talk test data (II): acquisition of concept test data

shell脚本中解决SCP命令免密登录
随机推荐
jmeter资料及软件
Tool class xmlutil (parse and return soap and XML messages to obtain the value of the target node)
345 leetcode ransom letter
k8s部署mysql
. net core uses iasyncexceptionfilter to capture global exceptions and return information uniformly
QT uses windeployqt Exe packaging program
2022-4-22 Leetcode 91.解码方法
毕业设计第8周学习记录
Introduction and hardware implementation of sereds deserialization module
Project tutorial of developing OA enterprise online office system based on SSM framework - with source code - graduation design
Adobe series error code solutions summary
Dernière version du filigrane + code source de l'applet CPS à emporter
2022 G3 boiler water treatment national question bank and online simulation examination
Shandong University project training raspberry pie promotion plan phase II (IX) inheritance and innovation
Selenium web自动化测试
JMeter data and software
解数独[Pre-DS-hash结构 + component-DFS | Pre-hash-1-9特性--二进制状态压缩 + DFS]
QT使用windeployqt.exe打包程序
swagger2 注解说明
344-Leetcode 二叉树的所有路径