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 08-01-2012, 08:05 PM   #1
luis84
LQ Newbie
 
Registered: Aug 2012
Posts: 1

Rep: Reputation: Disabled
Bash Script to SSH


Hello,

I need a bash script to ssh into a list of servers, and add a user and set the password.

I have seen a number of telnet scripts but none for ssh.

I want it to ask for the user and password at start, is this possible and are there any example scripts?

Thank you
 
Old 08-01-2012, 11:42 PM   #2
roger_heslop
Member
 
Registered: Oct 2009
Location: Leander, TX
Distribution: Fedora 20
Posts: 97

Rep: Reputation: 35
A few ideas:

You can push a script to a server using:

Code:
 ssh server1.mydomain.com 'bash -s' < script.sh
Withing that script, you can create a user using the useradd command, with a beginning default password using:

Code:
passwd $usr1 << EOF
P@ssw0rd
P@ssw0rd
EOF
Finally, you can use the 'chage' command to ensure the user will have to change the password on login, as long as the lastday ( -d ) and maxdays ( -M ) together add up to a date before the present. Use 'man' for details.

Good luck!
 
Old 08-01-2012, 11:47 PM   #3
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
If you want it to ask for the username and password at the start you might be better off with an expect script. There are many solutions to managing fleets of servers, heres my thoughts on a few:

- Some years ago I used cluster ssh quite happily, it required a little hotkey remapping to prevent conflict with [ctrl]+ combos but was solid otherwise.
- I also used puttycs when managing linux hosts from a windows pc, it was quite handy as you could create .cmd files with different sets of hosts.
- I've deployed func in the past, which provides great control using globbing for hostnames and runs simultaneously rather than sequentially.
- You could also implement a configuration management system such as puppet, it comes in open source or enterprise.

Configuration management is my current focus, it saves you having to work out who's been fiddling with what and why the system has stuff on it that you didn't put there.

Last edited by kbp; 08-01-2012 at 11:48 PM.
 
  


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
Bash script using scp and ssh Drigo Linux - Newbie 6 08-05-2011 05:04 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Running a bash script via ssh jhameier Linux - Newbie 4 04-09-2010 06:35 AM
ssh and bash script question babag Linux - Networking 4 06-28-2008 12:26 AM
ssh session within a bash script Tamaros Programming 1 05-11-2008 03:38 AM

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

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