linux - [Solved-5 Solutions] How to pass the password to su/sudo/ssh without overriding the TTY - ubuntu - red hat - debian - linux server - linux pc



Linux - Problem :

How to pass the password to susudossh without overriding the TTY ?

Linux - Solution 1:

For sudo there is a -S option for accepting the password from standard input.

 -S          The -S (stdin) option causes sudo to read the password from
                the standard input instead of the terminal device.
click below button to copy the code. By - Linux tutorial - team

This will allow you to run a command like:

echo myPassword | sudo -S ls /tmp
click below button to copy the code. By - Linux tutorial - team

As for ssh, To automate/script it's usage with no success. There doesn't seem to be any build-in way to pass the password into the command without prompting. As others have mentioned, the "expect" utility seems like it is aimed at addressing this dilemma but ultimately, setting up the correct private-key authorization is the correct way to go when attempting to automate this.

Linux - Solution 2:

Applescript which prompts for a password through a dialog box and then builds a custom bash command, like this:

echo <password> | sudo -S <command>
click below button to copy the code. By - Linux tutorial - team

If sudo accepted a pre-encrypted password, so you could encrypt it within script and not worry about echoing clear text passwords around.

Linux - Solution 3:

For ssh you can use sshpass -p "password" ssh user@host sshpass works. You need to download sshpass firs

Linux - Solution 4:

ssh user@host bash -c "echo mypass | sudo -S mycommand"
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 5:

SSH can be used with private-public key authentication. If the private key does not have a passphrase, ssh can be used without prompting for a password.


Related Searches to - linux - linux tutorial - How to pass the password to su/sudo/ssh without overriding the TTY