Script to change password on linux servers over ssh

后端 未结 17 2725
南方客
南方客 2020-12-08 11:22

We have a number of Red Hat linux servers in our IT environment. I am being asked by my team members to write a script (preferably shell script) to change a user\'s password

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 11:52

    Thought I should put my solution in an answer field - not sure if this should be a part of the question..

    OK, I have put together a partially working solution using Dennis' suggestion.

    servers.txt looks like:

    server1
    server2
    server3
    .
    .
    .
    

    I am using:

    for server in `cat servers.txt`; do
    ssh $server -l user 'passwd <

    This produces:

    user@server1's password: ****
    (current) UNIX password: New UNIX password: Retype new UNIX password: Changing password for user user.
    Changing password for user
    passwd: all authentication tokens updated successfully.
    user@server2's password: ****
    (current) UNIX password: New UNIX password: Retype new UNIX password: Changing password for user user.
    Changing password for user
    passwd: all authentication tokens updated successfully.
    

    So here, I still need to type my old password once for each server. Can this be avoided?

提交回复
热议问题