Ssh sudo pipe command

this command works

ssh -t www.foo.com 'sudo ls -l'

I immediately receive a request for my password, after entering I get the contents of the directory

If I try to execute this command, it will not work - I never ask for a password, so I never get any content.

ssh -t www.foo.com 'sudo ls -l' | grep 'foo'

This is a basic example, I know that I can pass / grep the output in my "ls" command. for my application, I need to pass the output through a program on my host.

+4
source share
4 answers
ssh -t www.foo.com 'echo your_pass | sudo -S ls -l' | grep 'foo'
0
source

It is also possible:

ssh -t www.foo.com 'sudo -S ls -l <~/passwd.txt' | grep 'foo'
0
source

sudo, /etc/sudoers ( , /etc/sudoers.d), . sudoers .

sudoers, ls root:

<yourusername> ALL = (root) NOPASSWD: /bin/ls

, , - , ls, , , . , .

.

0

, , , "ssh -t www.foo.com" sudo ls -l " , grepping " foo ". , .

.

, . ,

$ ssh -t user @host 'sudo ls -l /' | grep 'root' user @host password: <===== Then he expects the user to enter the password for the user sudo. The connection to the host is 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 this works for you.

0
source

All Articles