LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-16-2015, 03:31 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
Post 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.
 
Old 05-16-2015, 08:44 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
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.
 
1 members found this post helpful.
Old 05-16-2015, 09:14 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 05-16-2015, 11:59 AM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
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.
 
1 members found this post helpful.
Old 05-17-2015, 10:19 AM   #5
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
Quote:
Originally Posted by Keith Hedger View Post
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.
 
Old 05-17-2015, 11:01 AM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
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.
 
Old 05-17-2015, 11:50 PM   #7
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
My command is "SSH username@IP Address"
 
Old 05-18-2015, 02:11 AM   #8
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Use keys.
 
Old 05-18-2015, 03:48 AM   #9
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Quote:
Originally Posted by descendant_command View Post
Use keys.
+1

Code:
man ssh
 
Old 05-19-2015, 01:04 PM   #10
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by descendant_command View Post
Use keys.
just to elaborate:
http://linuxconfig.org/passwordless-ssh
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to enter data automatically on terminal? (script BASH) MattFly Programming 4 04-27-2015 07:08 AM
How to write a script which will take in the password automatically? thomas2004ch Linux - Software 1 03-21-2011 11:11 AM
Creating a script that will log into root and enter password and then run commands. tananthulus Linux - Newbie 8 11-02-2009 05:37 PM
How to enter a password before running script, with you irda remote controller ? frenchn00b Linux - General 1 11-17-2007 08:06 AM
automating scp copy, how to enter password via script? stefaandk Programming 3 11-29-2006 09:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration