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 busybox@xx.xx.xx.xx 'ssh modem@xx.xx.xx.xx'

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.

  • Add your public key to the file ~/.ssh/authorized_keys at busybox@xx.xx.xx.xx. – Cyrus Sep 27 '15 at 23:00

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
  • 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 Sep 27 '15 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 Sep 27 '15 at 23:47

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 busybox@xx.xx.xx.xx ssh modem@xx.xx.xx.xx

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 busybox@xx.xx.xx.xx ssh modem@xx.xx.xx.xx

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 busybox@xx.xx.xx.x 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 busybox@xx.xx.xx.xx ssh modem@xx.xx.xx.xx
  3. When you've finished, close the master connection with

    ssh -O exit busybox@xx.xx.xx.xx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.