Linux system bulk Modify user Password

Source: Internet
Author: User
Tags learn php

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% 22

192.168.18.218 root c87; ZNNL 22

# Cat Change_pass.sh

#!/bin/bash

Old_info=~/old_info

New_info=~/new_info

For IP in ' awk '/^[^#]/{print $ ' $OLD _info '; Do

User= ' awk-v i= $IP ' {if (i==$1) print $ ' $OLD _info '

Pass= ' awk-v i= $IP ' {if (i==$1) print $} ' $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 _info

Expect-c "

Spawn Ssh-p$port [email protected] $IP

Set Timeout 2

Expect {

\ "(yes/no) \" {Send \ "yes\r\"; Exp_continue}

\ "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% 22

192.168.18.218 root c87; ZNNL 22

Free pick up brother even it education original Linux OPS engineer video/Detailed Linux tutorials, details Inquiry official website customer Service: http://www.itxdl.net/linux/

Learn PHP, Linux, HTML5, UI, Android and other video tutorials (Courseware + notes + video)! Contact Q2430675018

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.