linux有些命令需要输入密码,比如ssh或su,又不能通过参数指定,正常只能手动输入。这让人多少有些懊恼,尽管这样很安全!

破解:expect

默认没这个东西,需要安装

 

apt/yum install -y expect

好了,可以使用了,先写个shell脚本

#!/usr/bin/expect#用expect执行下面脚本
spawn su#执行su命令
expect "Password:"#看到这样的文本时
exp_send "123123\r"#输入密码
interact#进入交互状态

vi su后将上面内容复制/输入即可

chmod +x su

添加执行权限

./su

运行,即可进入expect的交互环境。

 

push.sh

#!/usr/bin/expect
spawn git pull --rebase
expect "Username for 'https://github.com':"
exp_send "iqiy\r"
expect "Password for 'https://iqiy@github.com':"
exp_send "xxx\r"
interact

  

相关文章:

  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
  • 2023-02-20
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-08-18
  • 2021-06-08
  • 2021-08-31
  • 2021-08-05
  • 2023-03-17
相关资源
相似解决方案