Script to change password on linux servers over ssh

后端 未结 17 2749
南方客
南方客 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:45

    Building on squashbuff's example, I tried the following, which worked well for me:

    #!/bin/bash
    for server in `cat hostlist`; do
    echo $server;
    ssh username@$server 'passwd <<EOF
    old_password
    new_password
    new_password
    EOF';
    done

    Security wise, Could be improved to take input without echoing to the screen OR saving the plaintext to disk.

提交回复
热议问题