Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 08-01-2012, 09:05 PM   #1
LQ Newbie
Registered: Aug 2012
Posts: 1

Rep: Reputation: Disabled
Bash Script to SSH


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-02-2012, 12:42 AM   #2
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:

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

passwd $usr1 << 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-02-2012, 12:47 AM   #3
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-02-2012 at 12:48 AM.


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

All times are GMT -5. The time now is 07:35 AM.

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