Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Using sudo in the local machine will give you ZERO privileges in another machine, per se. The only situation when something like that would happen is if root itself has a ssh login enabled in the remote machine (and this is an extremely dangerous thing, unless it's somewhat mitigated by using keys and PermitRootLogin=without-password in /etc/ssh/sshd_config).
Furthermore, assuming you stopped using sudo in the local machine and wanted to pipe the password thru ssh to a remote sudo, it will also fail because sudo only read its password from a tty, which in the case of a normal ssh connection isn't allocated:
me@localhost:$ echo hello | ssh user@remotehost -t sudo cat
user@remotehost's password: ******
sudo: no tty present and no askpass program specified
You *could* force a tty allocation by ssh using the -t switch, and then type the password when the remote sudo asks: me@localhost:$ ssh user@remotehost -t sudo echo hello
user@remotehost's password: ******
[sudo] password for user: ******
hello
But this won't work when you want to pipe things to ssh: me@localhost:$ echo hello | ssh user@remotehost -t sudo cat
Pseudo-terminal will not be allocated because stdin is not a terminal.
user@remotehost's password: ******
sudo: no tty present and no askpass program specified
Redirect local command output to a remote sudo command
I'm aware that that sudo in the local machine will give me nothing on the remote machine.
The example I gave serves its purpose, but it's not exactly what I'm trying to do. The "symptoms", however, are identical.
For the record let's say that I would like to redirect the output of a local command that needs to be run as root (sudo) to a remote command that needs to be ran as root (sudo). And looking at your last example I see that output redirection per se isn't working with a remote sudo. So this is the issue that I would like to attack. Is there a way to "fix" this?
Is there a way to redirect local command output to a remote sudo command?
Only way I can think of to get it done is to add !tty_tickets,ticket_timeout=0.5 or something short like that to the remote user's sudo options, and do a separate sudo -v beforehand, so for the above substitute
The '(cat data | sudo cat)' avoids an annoying delay before sudo prompts for the password (because the redirect tells the shell to open the pipe before running sudo).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.