0

I've got a script which needs to do something on a remote system using SSH. Something of this sort:

#!/bin/bash
ssh -tt $@ sudo ash -c 'echo "8.8.8.8 dns.google.com" >> /etc/hosts'

If the user doesn't need to enter a password for sudo to work, this is fine. But I can't figure out how to allow the user running this script to enter the password for sudo. Ideas? The remote shell is busybox's ash.

Tom
  • 7,269
  • 1
  • 42
  • 69
  • doesn't it just ask user in the terminal window? – akostadinov Aug 28 '20 at 11:38
  • https://stackoverflow.com/questions/3980668/how-to-get-a-password-from-a-shell-script-without-echoing – Shubham Srivastava Aug 28 '20 at 11:40
  • Does this answer your question? [How to get a password from a shell script without echoing](https://stackoverflow.com/questions/3980668/how-to-get-a-password-from-a-shell-script-without-echoing) – Shubham Srivastava Aug 28 '20 at 11:40
  • @akostadinov The script as given above doesn't prompt at all, it just gives `sh: can't create /etc/hosts: Permission denied`. – Tom Aug 28 '20 at 11:57
  • Sort of. The extra complexity comes from the layers of quoting. This works: `echo Password:; read -s password; echo "${password}" | ssh -tt $@ sudo ash -c "'"'echo "8.8.8.8 dns.google.com" >> /etc/hosts'"'"` – Tom Aug 28 '20 at 12:02
  • Does the remote host allow you to login as root? That would be simpler than running `sudo` on the remote box. – chepner Aug 28 '20 at 14:19
  • Sadly, no. Yes, I could hack it so that I could log in as root, but it's an embedded system that gets re-installed every time I test it, so it's a lot easier to figure out how to make this work. – Tom Aug 28 '20 at 15:09
  • @Tom, but then it is not `sudo` that fails. It wouldn't return such error. – akostadinov Aug 28 '20 at 21:45

0 Answers0