Sponsored Content
Top Forums Shell Programming and Scripting A script to change password for all other servers Post 302992098 by Hiroshi on Tuesday 21st of February 2017 02:48:50 PM
Old 02-21-2017
A script to change password for all other servers

Hey Gurus,

I have this requirement to change the password for other servers remotely from one server. So, I installed public keys on all servers and wrote the following script to do the job. Something appears to be wrong with my loop, as it only changes one server and ignores the rest. I'm testing the script with a test data file with about 5 servers in it. The data file is the command-line argument to the script. Can you please tell me what's wrong and how to fix it?

As always, I truly appreciate this community effort. You guys are truly awesome; thank you very much.
Code:
#!/bin/bash
##data file name is passed in as argument to .sh script
filename="$1"
while  read -r line
do
        ##newPassword and username are placeholders
        ssh $line 'echo -e "TestPW\nTestPW" | passwd SomeUser'
done < "$filename"


Last edited by vbe; 02-21-2017 at 04:03 PM.. Reason: code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to script to logon servers using id and password

Hey.. I am new in scripting.. I know a little bit of scripting.. I am facing some problem.. I need to create a script using which I may log on to a server (e.g. ftp) with ID and password.. thus copy a particular file to a local dir.. the commands required to do that I do know.. I am able to do it... (1 Reply)
Discussion started by: razeeev
1 Replies

2. Shell Programming and Scripting

script to change passwords for the same user on multiple servers

I am trying to write a script to change passwords for the same user on multiple servers. My environment runs purely ssh / scp not rsh / rcp and therefore coping using rcp is not an option. I have been playing with expect to perform tasks but think there must be a better way. Has anyone got... (7 Replies)
Discussion started by: stolz
7 Replies

3. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

4. Red Hat

Change password of linux servers remotely

Hi, I am very bad at scripting. I need help from scripting experts... I need to change password of around 100 linux remote servers. I have been given a script for changing the password that automates the task. however I do not understand the usage and meaning of the script, the script is an... (0 Replies)
Discussion started by: renuka
0 Replies

5. Shell Programming and Scripting

Script:Change password on 1000+ servers

Hello Folks Scenario : I have a linux box (expect tool installed) which connects to 1000+ other boxes (either Solaris or AIX or Linux ) with a specific id and password using SSH. I now wish to write a script (Shell and/or expect and/or Python) which will change this existing password to a... (1 Reply)
Discussion started by: ak835
1 Replies

6. Solaris

Change passwd for bulk servers using SSH script

Hi, I need to Change passwd for bulk servers using SSH script. I have one server, from which i can reach all the servers without password via SSH. There is some expect script, from which i can achieve it. Can any one help me out here. Thanks in advance. Vicky (1 Reply)
Discussion started by: vickyingle5
1 Replies

7. Shell Programming and Scripting

Shell script to change the password on multiple servers in linux

Can any one please let me know the shell script to change the password for a particular user on multiple linux servers. (2 Replies)
Discussion started by: s_madras
2 Replies

8. Shell Programming and Scripting

Script for login to servers with user name and password and execute commands

I am having the 15 servers which need to do the monitoring Hi I need a shell script, By which i can log in to multiple servers and execute the commands.. I need to specify the username and password in the scripts. Please help me to write the script so that it can login with username and... (5 Replies)
Discussion started by: nandan8a
5 Replies

9. AIX

How to write a script to run without password on a batch of servers?

I need run a command such as ps -ef |grep xxx on a batch of servers, how to write a script to run it without password? don't need go in each server to check? Thanks (7 Replies)
Discussion started by: rainbow_bean
7 Replies

10. Shell Programming and Scripting

Shell script to set user password to never expire in UNIX servers

Hi, I have a requirement where in i need to write a shell script to set users password to never expire. I know the command which is used to perform the same .. which is chage command. But, could not figure out how to do the same in shell script. Could you please help me with the shell... (3 Replies)
Discussion started by: suren424
3 Replies
PASSWD(1)                                                          User Commands                                                         PASSWD(1)

NAME
passwd - change user password SYNOPSIS
passwd [options] [LOGIN] DESCRIPTION
The passwd command changes passwords for user accounts. A normal user may only change the password for his/her own account, while the superuser may change the password for any account. passwd also changes the account or associated password validity period. Password Changes The user is first prompted for his/her old password, if one is present. This password is then encrypted and compared against the stored password. The user has only one chance to enter the correct password. The superuser is permitted to bypass this step so that forgotten passwords may be changed. After the password has been entered, password aging information is checked to see if the user is permitted to change the password at this time. If not, passwd refuses to change the password and exits. The user is then prompted twice for a replacement password. The second entry is compared against the first and both are required to match in order for the password to be changed. Then, the password is tested for complexity. As a general guideline, passwords should consist of 6 to 8 characters including one or more characters from each of the following sets: o lower case alphabetics o digits 0 thru 9 o punctuation marks Care must be taken not to include the system default erase or kill characters. passwd will reject any password which is not suitably complex. Hints for user passwords The security of a password depends upon the strength of the encryption algorithm and the size of the key space. The legacy UNIX System encryption method is based on the NBS DES algorithm. More recent methods are now recommended (see ENCRYPT_METHOD). The size of the key space depends upon the randomness of the password which is selected. Compromises in password security normally result from careless password selection or handling. For this reason, you should not select a password which appears in a dictionary or which must be written down. The password should also not be a proper name, your license number, birth date, or street address. Any of these may be used as guesses to violate system security. You can find advice on how to choose a strong password on http://en.wikipedia.org/wiki/Password_strength OPTIONS
The options which apply to the passwd command are: -a, --all This option can be used only with -S and causes show status for all users. -d, --delete Delete a user's password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless. -e, --expire Immediately expire an account's password. This in effect can force a user to change his/her password at the user's next login. -h, --help Display help message and exit. -i, --inactive INACTIVE This option is used to disable an account after the password has been expired for a number of days. After a user account has had an expired password for INACTIVE days, the user may no longer sign on to the account. -k, --keep-tokens Indicate password change should be performed only for expired authentication tokens (passwords). The user wishes to keep their non-expired tokens as before. -l, --lock Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a '!' at the beginning of the password). Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators should use usermod --expiredate 1 (this set the account's expire date to Jan 2, 1970). Users with a locked password are not allowed to change their password. -n, --mindays MIN_DAYS Set the minimum number of days between password changes to MIN_DAYS. A value of zero for this field indicates that the user may change his/her password at any time. -q, --quiet Quiet mode. -r, --repository REPOSITORY change password in REPOSITORY repository -R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. -S, --status Display account status information. The status information consists of 7 fields. The first field is the user's login name. The second field indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age, maximum age, warning period, and inactivity period for the password. These ages are expressed in days. -u, --unlock Unlock the password of the named account. This option re-enables a password by changing the password back to its previous value (to the value before using the -l option). -w, --warndays WARN_DAYS Set the number of days of warning before a password change is required. The WARN_DAYS option is the number of days prior to the password expiring that a user will be warned that his/her password is about to expire. -x, --maxdays MAX_DAYS Set the maximum number of days a password remains valid. After MAX_DAYS, the password is required to be changed. CAVEATS
Password complexity checking may vary from site to site. The user is urged to select a password as complex as he or she feels comfortable with. Users may not be able to change their password on a system if NIS is enabled and they are not logged into the NIS server. passwd uses PAM to authenticate users and to change their passwords. FILES
/etc/passwd User account information. /etc/shadow Secure user account information. /etc/pam.d/passwd PAM configuration for passwd. EXIT VALUES
The passwd command exits with the following values: 0 success 1 permission denied 2 invalid combination of options 3 unexpected failure, nothing done 4 unexpected failure, passwd file missing 5 passwd file busy, try again 6 invalid argument to option SEE ALSO
chpasswd(8), passwd(5), shadow(5), usermod(8). shadow-utils 4.5 01/25/2018 PASSWD(1)
All times are GMT -4. The time now is 01:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy