git与expect联合使用免密登录

1. 安装expect

sudo apt-get install expect

2. 创建.sh脚本,并编写一下内容:

#!/usr/bin/expect
spawn git pull origin master
expect "Username"
send "username\n"
expect "Password"
send "password\n"
expect eof 

3. 执行.sh脚本

chmod a+x  script.sh 或chmod 755 script.sh

然后使用./script.sh的方式执行脚本.

其中第一行,必须加上#!/usr/bin/expect,表明是使用expect命令来执行以下命令.

注意,不要使用sh来执行.sh脚本,因为作为sh 命令行参数来运行,那么脚本的#! 的一行就会失效。

 

posted @ 2020-07-28 17:05  瞬_冷  阅读(677)  评论(0)    收藏  举报