Reputation: 5135
this command works
ssh -t www.foo.com 'sudo ls -l'
I immediately get asked for my password, once entered I get the directory contents
if I try to pipe this command it fails - I never get asked my password so I never get any contents.
ssh -t www.foo.com 'sudo ls -l' | grep 'foo'
This is a basic example, I know I could pipe/grep the output in my "ls" command. for my application I need to pipe the output through a program on my host.
Upvotes: 5
Views: 3962
Reputation: 173
The reason you are not getting prompt for password is because you are feeding the output of "ssh -t www.foo.com 'sudo ls -l'" to the pipe where you are grepping for 'foo'. So in this case the password prompt won't be shown, but actually the process is waiting for your input.
Try giving the password on the blank new line you get after running the command.
I tried this and it worked. Just for example,
$ ssh -t user@host 'sudo ls -l /' | grep 'root' user@host's password: <===== After this, it waits for user input to feed the password for sudo user. Connection to host closed. drwxr-xr-x 2 root root 4096 2011-08-31 15:33 bin dr-xr-xr-x 24 root root 4096 2014-07-14 00:52 bldmnt dr-xr-xr-x 2 root root 4096 2011-03-23 15:51 blr drwxr-xr-x 3 root root 4096 2011-08-31 15:36 boot . . .
Try it and see if it works for you.
Upvotes: 0
Reputation: 37770
In order to not be asked for a password to issue sudo commands, you need to have an entry in /etc/sudoers
(or better, a file in /etc/sudoers.d
) that lets you do it. There is a nice question on using sudoers here.
A sudoers config to allow you to run ls
as root could be:
<yourusername> ALL = (root) NOPASSWD: /bin/ls
One thing to look out for is that ls
is quite likely to be a shell built-in, so you may have trouble allowing it. You should be able to set your shell to defer to the system binary instead.
Trying to push your real password through it is not a secure solution.
Upvotes: 1
Reputation: 1782
Also possible:
ssh -t www.foo.com 'sudo -S ls -l <~/passwd.txt' | grep 'foo'
Upvotes: 0