LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-18-2014, 05:09 AM   #1
pugazhendhi_r@yahoo.com
LQ Newbie
 
Registered: Jul 2014
Posts: 23

Rep: Reputation: Disabled
Automate SSH in bash scripts


Hi All,
I have 54 servers, need to run daily monitoring and utilization scripts at peak hours. I created a cron job in each server and redirected it to a file. Then i will scp to a server. The problem is to frequently need to change to script.
Is there any possibility to automate ssh without prompting for password only in bash scripts but not like ssh-key-gen (passwordless authentication)


Thanks
 
Old 12-18-2014, 05:28 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You make ssh ask password for once and then you can run as many times as possible.

You have to do:

1) Run
ssh-agent
It will show some output. Just export shown variables in the shell

2) Next run
ssh-add
It will ask for password for the key
Give it.

3) And from now on no password would be asked.

For using shell script to automate; I don't know the way.
 
Old 12-18-2014, 05:33 AM   #3
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by pugazhendhi_r@yahoo.com View Post
but not like ssh-key-gen (passwordless authentication)
Why not?
 
Old 12-18-2014, 05:52 AM   #4
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,620

Rep: Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695Reputation: 2695
automate ssh

1. There is a lot of automation available directly in OpenSSH. I am not sure why you would avoid using keys, because that is the easiest way. Check the file options, config in .ssh folders, etc.

2. There are ssh tools NOT in the OpenSSH tree that allow password specifications in file, stored configuration, or on the command line. Command-line is NOT secure (anyone with a shell can see your passwrod if they look at the right time) but it can work. Examples: the putty tools for linux, lftp.

3. My preferred methods include using an rsyslogd server and logging all important metrics to non-standard log files over syslogd. That way the only load on the production is actually running the capture, all report extracts run on or against the log server taking that load off of production.

4. I workined on PSSP for a few years, and learned to recreate commands like dsh to propogate a command or scvript execution over any number of hosts from one management console (or my workstation). I did use keys, and recommend using keys, but there are MAY other options, and every fully experienced sysadmin has a few. If nothing you find fits you, get creative. Your own solution may fit your environment and use case better than ANYONE elses ideas.
 
Old 12-18-2014, 07:45 AM   #5
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
Quote:
Originally Posted by pugazhendhi_r@yahoo.com View Post
Is there any possibility to automate ssh without prompting for password only in bash scripts but not like ssh-key-gen (passwordless authentication)
if I've understood you correctly, you need sshpass utility intended for passing a password through ssh without typing it on every connection, e.g. from script.
 
Old 12-18-2014, 08:00 AM   #6
pugazhendhi_r@yahoo.com
LQ Newbie
 
Registered: Jul 2014
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by descendant_command View Post
Why not?
it will make that user to access without password in future whenever want to access know so need to access only when script need to run
 
Old 12-18-2014, 01:11 PM   #7
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by pugazhendhi_r@yahoo.com View Post
it will make that user to access without password in future whenever want to access know so need to access only when script need to run
You can specify a separate identity file with -i, then you can remove that file when access should be denied.
 
Old 12-18-2014, 06:05 PM   #8
LeoPap
Member
 
Registered: Jan 2013
Distribution: Centos
Posts: 99
Blog Entries: 1

Rep: Reputation: 10
Did you managed to do it?
 
Old 12-18-2014, 06:14 PM   #9
pugazhendhi_r@yahoo.com
LQ Newbie
 
Registered: Jul 2014
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Teufel View Post
if I've understood you correctly, you need sshpass utility intended for passing a password through ssh without typing it on every connection, e.g. from script.
sshpass is very useful.... i tried
 
  


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
LXer: Using Autokey Scripts to Automate Your Linux Desktop LXer Syndicated Linux News 0 05-12-2013 01:11 PM
running bash scripts over ssh connection babag Linux - Newbie 1 05-27-2008 11:07 PM
Shell Scripts and Networking to Automate macchanger fultron Linux - Newbie 1 02-16-2007 08:02 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
automate running scripts windyang12 Linux - Software 3 10-17-2003 11:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:35 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