# Linux批量创建用户并修改密码 **Repository Path**: myhfw003/linux_newusers_chpasswd ## Basic Information - **Project Name**: Linux批量创建用户并修改密码 - **Description**: Linux批量创建用户并修改密码 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2020-10-04 - **Last Updated**: 2021-08-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Linux批量创建用户并修改密码 #### 介绍 Linux批量创建用户并修改密码 ### 一、第一种方式 1. 创建用户文件utxt,如下: ``` abc01:x:1001:0::/home/abc01:/sbin/bash abc02:x:1002:0::/home/abc02:/sbin/bash abc03:x:1003:0::/home/abc03:/sbin/bash abc04:x:1004:0::/home/abc04:/sbin/bash abc05:x:1005:0::/home/abc05:/sbin/bash abc06:x:1006:0::/home/abc06:/sbin/bash abc07:x:1007:0::/home/abc07:/sbin/bash ``` 2. 执行 newusers utxt 3. 创建用户密码文件upw,如下: ``` abc01:123456 abc02:123456 abc03:123456 abc04:123456 abc05:123456 abc06:123456 abc07:12345 ``` 4. 执行 chpasswd < upw ### 第二种方式(第一种方式实测可以切换用户但无法登录,尝试另一种方式) 1. 创建用户列表文件userlist,如下: ``` c40201 c40202 c40203 c40204 c40205 c40206 c40207 c40208 c40209 c40210 c40211 c40212 c40213 c40214 c40215 c40216 c40217 c40218 c40219 c40220 c40221 c40222 c40223 c40224 c20149 c20122 c20504 c20514 c20508 c20607 c40115 c10219 c10114 c20604 c20608 c20527 c20531 c20605 ``` 2. 编写sheel脚本文件generateuser.sh,如下: ``` for username in $(cat userlist) do echo $username useradd -g root $username echo "113" | passwd --stdin $username done ``` 这样建立的用户都在root组里,密码为113 3. (如有必要)编写脚本文件deluser.sh,如下: ``` for username in $(cat userlist) do userdel -r $username done ``` 将删除用户列表中列出的所有用户