Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux expect

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Expect-c "set timeout-1; spawn ssh root@192.168.6.132; expect {* (yes/no) * {send yes\ r; exp_continue;} * password* {send 123456\ r; exp_continue;} eof {exit 0}}"; through the expect tool, shell completes password-free login script 1 during the service in the while loop. The prerequisite is to install expect package 2. The code is as follows: #! / bin/sh# master server password password=123456while read hostname; do expect-c "set timeout-1; spawn ssh-copy-id ${hostname}; expect {" * password:* "{send-- ${password}\ r; exp_continue;}" *\ (yes/no\) * "{send-- yes\ r; exp_continue;} eof {exit 0 }} "echo" hosts:$ {hostname} done. "# ipconf.cfg stores the ip of the user who wants to log in secret-free with the master server, for example: root@1921.68.245.134, the format of each line is the same as this example done < ipconf.cfgifconf.cfg example: root@192.168.6.132 root@192.168.6.133

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report