LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I Enter password automatically for an Script? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-enter-password-automatically-for-an-script-4175542746/)

hack3rcon 05-16-2015 03:31 AM

How can I Enter password automatically for an Script?
 
Hello.
How can I write an Script that enter my password for "sudo" command automatically?
for example, I want to run a command that need root permission and when I write it in a bash script, it ask me "sudo" password for user but how can I automate it?
Can it possible for other program like logging via SSH too?

Thank you.

ondoho 05-16-2015 08:44 AM

you can add an entry to /etc/sudoers that will enable the user of the script to gain root privileges only for that command, without having to enter a password.

check out https://wiki.archlinux.org/index.php...xample_Entries

if you're still stuck, show us what you got so far.

TobiSGD 05-16-2015 09:14 AM

If you don't want to change your sudo configuration, have a look at the Expect scripting language, which is designed exactly for this purpose.

Keith Hedger 05-16-2015 11:59 AM

Very insecure but if it's only run on your machine by you you can use
Code:

echo "mypassword"|sudo -S /path/to/command
This just infroms sudo to get the password from stdin.

hack3rcon 05-17-2015 10:19 AM

Quote:

Originally Posted by Keith Hedger (Post 5363283)
Very insecure but if it's only run on your machine by you you can use
Code:

echo "mypassword"|sudo -S /path/to/command
This just infroms sudo to get the password from stdin.

Not worked :(
I mean is that when I want connect to a system via SSH it put the username and password automatically and not ask me on the monitor.

Keith Hedger 05-17-2015 11:01 AM

ssh is NOT sudo you are confusing two differernt commands that ask for two different passwords pleas epost the command you are tring to run.

hack3rcon 05-17-2015 11:50 PM

My command is "SSH username@IP Address"

descendant_command 05-18-2015 02:11 AM

Use keys.

Keith Hedger 05-18-2015 03:48 AM

Quote:

Originally Posted by descendant_command (Post 5363910)
Use keys.

+1

Code:

man ssh

ondoho 05-19-2015 01:04 PM

Quote:

Originally Posted by descendant_command (Post 5363910)
Use keys.

just to elaborate:
http://linuxconfig.org/passwordless-ssh


All times are GMT -5. The time now is 02:55 PM.