Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with sudo? #7

Open
slhck opened this issue Dec 11, 2019 · 8 comments
Open

How to use with sudo? #7

slhck opened this issue Dec 11, 2019 · 8 comments

Comments

@slhck
Copy link

slhck commented Dec 11, 2019

When running sudo I get:

$ sudo su
[E] test2.example.com -> sudo: no tty present and no askpass program specified
[E] test.example.com -> sudo: no tty present and no askpass program specified
[E] example.com -> sudo: no tty present and no askpass program specified

Is there any way to circumvent this?

@boussou
Copy link

boussou commented Aug 26, 2020

it is ssh problem (or say security measure), you should use "sudo yourcmd" each time

@dermoumi
Copy link

dermoumi commented Dec 9, 2021

it is ssh problem (or say security measure), you should use "sudo yourcmd" each time

No, sudo yourcmd shows the same error because it asks for the password and hss doesn't provide a tty (i think?), i'm still looking for a solution

@avently
Copy link

avently commented Jul 13, 2022

@six-ddc could you please suggest how to deal with the inability to run a command with sudo?
I tried hss -H '-tt hostname' but hss can't work this way. What is an alternative solution that works for you?

@six-ddc
Copy link
Owner

six-ddc commented Jul 18, 2022

@avently As mentioned above, If your sudo cmd requires a password, it is not supported in batch mode like hss(no tty), maybe you should setup no-password in /etc/sudoers. https://askubuntu.com/questions/334318/sudoers-file-enable-nopasswd-for-user-all-commands

@avently
Copy link

avently commented Jul 18, 2022

I could setup it but I prefer to enter a password because this way I know when scripts I run require a sudo command execution (which is not always a good idea so I can Ctrl C in this case).

Is it possible to support providing tty somehow (technically)?

P.S. I made a bash function that can run commands with sudo cmd on a list of servers but it can't work in parallel because if no tty too

@slhck
Copy link
Author

slhck commented Jul 18, 2022

I have given up on finding a solution for this with bash tools. I now use Ansible for such tasks. It handles sudo well. Use the ad hoc mode to run arbitrary commands.

Basically, you can set up an inventory file and then run:

ansible all --ask-become-pass --become -a 'apt install blah'

This will run the command with sudo on all (all) hosts defined in the inventory.

@six-ddc
Copy link
Owner

six-ddc commented Jul 18, 2022

@avently Try this way echo <password> | sudo -S <command>. One command, and 'sudo' explicitly.

@avently
Copy link

avently commented Jul 18, 2022

@six-ddc this trick will work only if you have the same password on all servers and you want to run one command with root. Also it's not a good thing for security to have password printed in a list of processes. So, better to use for such cases one-liner in bash which allows to enter a password in a right way. Or to use Ansible, as stated above.
If it's technically possible, I would prefer native support in hss.

For example, using this command I almost able to enter a password, but hss doesn't work this way correctly:

hss -H '-tt host'
$ sudo ls
(shows nothing)
^C
(prints) [sudo] password for user: $ ^C

So close to solution:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants