Note: Please go to docs.rightscale.com to access the current RightScale documentation set. Also, feel free to Chat with us!
Home > FAQs > How can I change passwords remotely on many hosts using a scripted method?

How can I change passwords remotely on many hosts using a scripted method?

Table of Contents

Background

This article attempts to provide a script for changing a linux user's password across multiple hosts.

Answer

The following script could be used as a Rightscript in the dashboard. Be sure to fill in inputs where necessary for HOSTS and PASSWORD:

#!/bin/bash

for host in $HOSTS; do ssh root@$host "usermod -p $PASSWORD $USERNAME"; done

This simple one liner will take multiple values for $HOSTS (space separated), then SSH into each (as the root user) and issue the usermod command to change $USERNAME's password to a value of $PASSWORD.

This may be useful in some scenarios, and it can be made a bit more powerful if needed. For example:

#!/bin/bash

for host in $HOSTS; do ssh root@$host "usermod -p `perl -e 'print crypt("change-me", "salt")'` $USERNAME"; done

This will iterate through all hosts and generate a random password using the crypt function. Simply change 'change-me' to a value of your choosing and ensure inputs are filled in as needed.

You must to post a comment.
Last modified
21:28, 16 May 2013

Tags

Classifications

This page has no classifications.

Announcements

None


© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.