How to pass the password to su/sudo/ssh without overriding the TTY?
For sudo there is a -S option for accepting the password from standard input. Here is the man entry:
-S The -S (stdin) option causes sudo to read the password from
the standard input instead of the terminal device.
This will allow you to run a command like:
echo myPassword | sudo -S ls /tmp
As for ssh, I have made many attempts 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.
SSH: How to know the password of sudo users created automatically by gcloud?
- You can change the passport by first elevating to root user:
sudo su -
- Then change the password for the user in question:
Is there a way to automatically pass a password to sudo without having to type it in?
Let’s say your password was in the file called
Pipe it into
echo password | sudo -S rm /path/to/item
Sort a List With Lowercase First
How to Send a File as an Email Attachment Using Linux Command Line
Bash Script Prints "Command Not Found" on Empty Lines
Add a Prefix String to Beginning of Each Line
Is There Any API For Determining the Physical Address from Virtual Address in Linux
Hello, World in Assembly Language With Linux System Calls
How to Add Users to Docker Container
Automating Telnet Session Using Bash Scripts
Make -J 8 G++: Internal Compiler Error: Killed (Program Cc1Plus)
Uninstall Node.Js Using Linux Command Line
How to Fix 'Sudo: No Tty Present and No Askpass Program Specified' Error
Using Openssl to Get the Certificate from a Server
"Failed to Load Platform Plugin "Xcb" " While Launching Qt5 App on Linux Without Qt Installed
How Are the Fs/Gs Registers Used in Linux Amd64
Bash Script Process Substitution Syntax Error: "(" Unexpected
How to Create Docker Overlay Network Between Multi Hosts