sshpass 自动输入ssh密码原创

# Linux sshpass

在Linux 下可以用sshpass 实现密码自动输入

yum install sshpass

#命令行执行
sshpass -p xxxx -e ssh root@192.168.0.122 -o StrictHostKeyChecking=no

#从文件读取密码
echo "password" > userpasswd
sshpass -f userpasswd ssh username@x.x.x.x
#从环境变量获取密码
export SSHPASS="password"
sshpass -e ssh username@x.x.x.x 

# 与 rsync 混用
sshpass -p XXXX rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no" remote_user@remote_host:/remote/dir /local/dir 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

在windows 下安装sshpass 比较麻烦,可用plink 替换
首先下载cygnative

http://diario.beerensalat.info/2009/08/18/new_cygnative_version_1_2_for_rsync_plink.html

下载plink
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

# 命令行执行
plink.exe -C -ssh -pw XXXXXX root@remote_host

# 与 rsync 混用
rsync -vzrtog --delete --progress  /local/dir -e "./tools/cygnative ./tools/plink.exe -pw XXXXXX" root@remote_host:/remote/dir

1
2
3
4
5
6
上次更新: 2022/12/05, 22:29:05

Initializing...

最近更新
01
git的tag与branch 原创
05-21
02
阿里云SLS日志服务的数据脱敏及安全管理 原创
03-21
03
云平台的成本管理 原创
03-13
更多文章>
×