自动连接的脚本

本文介绍了一种使用bash脚本和expect脚本来实现SSH远程自动化登录的方法。通过交互式输入用户名和IP地址,并预设密码的方式,简化了SSH登录过程。此方案适用于需要频繁进行远程登录操作的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1 #!/bin/bash
  2 read -p 'user:'  USER
  3 read -p 'ipaddr:'  IP
  4 ssh $USER@$IP

  1 #!/usr/bin/expect
  2 set USER [ lindex $argv 0 ]
  3 set IP [ lindex $argv 1 ]
  4 set PASSWD [ lindex $argv 2 ]
  5 spawn /mnt/ssh.sh
  6 expect {
  7         "Are you sure" { send "yes\r"; exp_continue }
  8         "user" { send "$USER\r"; exp_continue }
  9         "ipaddr" { send "$IP\r"; exp_continue }
 10         "password" { send "$PASSWD\r"; exp_continue }
 11 expect eof
 12 }
 13 interact
~               
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值