1

I currently am attempting to reboot a modem via ssh using a bash script. For reasons I don't feel like explaining, I NEED to start on an ubuntu server computer, ssh into a setup running busybox 1.21.1 and then ssh into the modem from there and reboot it.

I need the busybox system to automatically input the password when sshing into the modem.

To do this when sshing into the busybox system from the ubuntu server, I use sshpass in the following:

sshpass -p password ssh [email protected] 'ssh [email protected]'

and running this gets me to the password prompt for the modem.

My problem is that the busybox system only has a small amount of commands available for use and none of them are sshpass or expect, which are the only two commands I know to use to automatically interact with the ssh password prompt.

The defined functions on the busybox installation are

[, [[, addgroup, adduser, ar, arping, ash, awk, basename, blkid, bunzip2, bzcat,
cat, catv, chattr, chgrp, chmod, chown, chroot, chrt, chvt, cksum, clear, cmp,  
cp, cpio, crond, crontab, cut, date, dc, dd, deallocvt, delgroup, deluser, devmem, 
df, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, echo,
egrep, eject, env, ether-wake, expr, false, fdflush, fdformat, fgrep, find, fold,
free, freeramdisk, fsck, fuser, getopt, getty, grep, gunzip, gzip, halt, hdparm,
head, hexdump, hostid, hostname, hwclock, id, ifconfig, ifdown, ifup, inetd, init, 
insmod, install, ip, ipaddr, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kill, 
killall, killall5, klogd, last, less, linux32, linux64, linuxrc, ln, loadfont, 
loadkmap, logger, login, logname, losetup, ls, lsattr, lsmod, lsof, lspci, lsusb, 
lzcat, lzma, makedevs, md5sum, mdev, mesg, microcom, mkdir, mkfifo, mknod, mkswap,
mktemp, modprobe, more, mount, mountpoint, mt, mv, nameif, netstat, nice, nohup,
nslookup, od, openvt, passwd, patch, pidof, ping, pipe_progress, pivot_root, 
poweroff, printenv, printf, ps, pwd, rdate, readlink, readprofile, realpath,
reboot, renice, reset, resize, rm, rmdir, rmmod, route, run-parts, runlevel, sed, 
seq, setarch, setconsole, setkeycodes, setlogcons, setserial, setsid, sh, sha1sum, 
sha256sum, sha3sum, sha512sum, sleep, sort, start-stop-daemon, strings, stty, su,
sulogin, swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar, tee, 
telnet, test, tftp, time, top, touch, tr, traceroute, true, tty, udhcpc, umount, 
uname, uniq, unix2dos, unlzma, unxz, unzip, uptime, usleep, uudecode, uuencode,
vconfig, vi, vlock, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, 
xzcat, yes, zcat

Does anyone know of anything I can use to automatically input this password when sshing from the the busybox system into the modem?

Any help or ideas would be appreciated

EDIT: ssh key authentication is a no go due to lack of support from the modem.

Edit2: could someone at least comment and let me know if the question I'm asking makes that much sense? Trying hard to get a clear explanation of my problem so someone with the real know how can help me. Let me know if there's any part to my question that is confusing or if there is more detail I can provide.

1
  • Add your public key to the file ~/.ssh/authorized_keys at [email protected].
    – Cyrus
    Commented Sep 27, 2015 at 23:00

2 Answers 2

0

You need to use expect (or similar such as perl's Expect.pm module, or even perl's Net::SSH module...or the python pexpect module if you prefer python) on your Ubuntu server to:

  • connect to the busybox system, either with a password or with a key
  • when you get a shell prompt, issue the ssh command to get to the modem
  • when you see the password prompt, send the password
  • issue whatever commands you need to the modem
  • exit from the modem, and then from the busybox server
2
  • So you're saying the expect command will work if run from the ubuntu server and won't matter if expect isnt installed in the busybox system?
    – wvu_evan12
    Commented Sep 27, 2015 at 23:27
  • Yep. Your expect script will run on the ubuntu server, connect to busybox server and then connect to the modem. i.e. it runs entirely on the ubuntu server.
    – cas
    Commented Sep 27, 2015 at 23:47
0

If you have a key to authenticate to the intermediate BusyBox system and you need the password for the final system, just call sshpass on the original Ubuntu system, and call ssh -t to reach the BusyBox system so that there will be a terminal for the inner ssh command to read its password.

sshpass -p modempassword ssh -t [email protected] ssh [email protected]

If you also need to use a password for the BusyBox system, you'll need to call sshpass twice.

sshpass -p busyboxpassword sshpass -p modempassword ssh -t [email protected] ssh [email protected]

If for some reason you're having trouble with the connection setup, you can do it in two steps:

  1. Open up a master connection to the BusyBox system. This only requires support on the client, nothing special on the server.

    sshpass -p busyboxpassword ssh -o ControlMaster=auto -f [email protected] sleep 999999999
    
  2. Use a slave connection to the BusyBox system to open a connection to the modem.

    sshpass -p modempassword ssh -o ControlMaster=auto -t [email protected] ssh [email protected]
    
  3. When you've finished, close the master connection with

    ssh -O exit [email protected]
    

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.