Linux system bulk Modify user Password

Source: Internet
Author: User

Scripting Purpose: bulk modification of Linux system user passwords

Condition: The user who must be modified is root because only root has permission to use the passwd command

Description: the IP, user, password, port information is written to the Old_info file, the script reads the corresponding information from this file, using the expect-free interactive landing system. Modify the randomly generated 8-bit password to the root user's new password. Then save the new password to the Net_info file.


# cat old_info #     ip      user    passwd    port#----------------------- -------------------------192.168.18.217  root    n8wx3mu%      22192.168.18.218  root    c87; Znnl     22 
# cat change_pass.sh#!/bin/bashold_info=~/old_infonew_info=~/new_infofor ip in  ' awk   '/^[^#]/{print $1} '   $OLD _info ';  do    user= ' awk -v i= $IP   ' {if (i==$1) print $2} '   $OLD _info '     pass= ' awk -v i= $IP   ' {if (i==$1) print $3} '   $OLD _info '     port= ' awk -v i= $IP   ' {if (i==$1) print $4} '   $OLD _info '     new_pass= ' mkpasswd -l 8 '      echo  "$IP     $USER     $NEW _pass         $PORT " >>  $NEW _infoexpect -c "     spawn ssh -p$ Port [email protected] $IP     set timeout 2     Expect {        \ "(yes/no) \"  {send \ "yes\r\"; exp_ Continue}    &nbSp;   \ "Password:\"  {send \ "$PASS \r\";exp_continue}         \ "[email protected]*\"  {send \ "echo \ ' $NEW _pass\ '  |passwd -- stdin  $USER \r exit\r\ "; exp_continue}        #\" [email  Protected]*\ "  {send \" df -h\r exit\r\ "; exp_continue}    }" done
# cat New_info 192.168.18.217 root n8wx3mu% 22192.168.18.218 root c87; ZNNL 22


This article is from the "Li Zhenliang Technology Blog" blog, make sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1674791

Linux system bulk Modify user Password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.