在linux系统上创建用户,要求如下:

1)以全班同学的姓名拼音为用户名,创建所有同学的相应用户

2)设置每个用户的家目录为:/home/学号加用户名

3)设置每个用户的shell为:/sbin/nologin

4)设置每个用户的备注为:rongxin107student

5)建立组:rongxin,把所有用户加入到组中

a)建立分组:groupadd rongxin

b)用vim 编辑器编写一个students.txt的文档第一列为学号,第二列为姓名

c)创建用户编写shell脚本 :

 vim /a.sh

#!/bin/bash

name=(`cut -d " "-f2 students.txt `)

numeber=(`cut -d " "-f1 students.txt`)

sum=${#name[@]}

for ((i=0;i<$sum;i++))

do

    useradd -g rongxin ${name[$i]} -d /home/${number[$i]}$[name[$i]} -s /sbin/nologin -c rongxin107student

    echo ${number[$i]}| passwd --stdin ${name[$i]}

    echo "${name[$i]} created success"

done

d)删除用户的shell脚本

vim /b.sh

#!/bin/bash

name=(`cut -d " "-f2 students.txt `)

sum=${#name[@]}

for ((i=0;i<$sum;i++))

do

    usedel -r ${name[$i]}

done