LinuxQuestions.org
Register a domain and help support LQ
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, 04:31 AM   #1
hack3rcon
Member
 
Registered: Jan 2015
Posts: 928

Rep: Reputation: Disabled
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, 09:44 AM   #2
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

Rep: Reputation: 837Reputation: 837Reputation: 837Reputation: 837Reputation: 837Reputation: 837Reputation: 837
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, 10:14 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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, 12:59 PM   #4
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,253

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
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.
 
Old 05-17-2015, 11:19 AM   #5
hack3rcon
Member
 
Registered: Jan 2015
Posts: 928

Original Poster
Rep: Reputation: Disabled
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, 12:01 PM   #6
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,253

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
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-18-2015, 12:50 AM   #7
hack3rcon
Member
 
Registered: Jan 2015
Posts: 928

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

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Use keys.
 
Old 05-18-2015, 04:48 AM   #9
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,253

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

Code:
man ssh
 
Old 05-19-2015, 02:04 PM   #10
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,176

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:08 AM
How to write a script which will take in the password automatically? thomas2004ch Linux - Software 1 03-21-2011 12:11 PM
Creating a script that will log into root and enter password and then run commands. tananthulus Linux - Newbie 8 11-02-2009 06:37 PM
How to enter a password before running script, with you irda remote controller ? frenchn00b Linux - General 1 11-17-2007 09:06 AM
automating scp copy, how to enter password via script? stefaandk Programming 3 11-29-2006 10:57 AM


All times are GMT -5. The time now is 08:47 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration