同时创建多个账号并设置密码

 
服务器需要提供给大家一人一个账号进行教学.
  忙了了天,才算初步完成了系统管理的第一步.
  首先声明,GOOGLE我已经几乎搜遍相关问题,不过真正能解决问题的少得可以忽略!!

创建账号脚本:

#!/bin/bash
#This is gnuser's first Bash Shell program
#Today the BOSS tell me to manage the server PC
#First ,I must remove all of the previous accounts
#Second ,I must create all of the classmates' accounts use of their names

pswd=`perl -e ' { printf crypt("123456","ab") . "/n" }'`
for i in `cat name`
        do
                useradd -m -g users -s /bin/bash  -p $pswd "$i"

                sleep 1
        done

删除账号脚本

#!/bin/bash
#This is gnuser's first Bash Shell program
#Today the BOSS tell me to manage the server PC
#First ,I must remove all of the previous accounts
#Second ,I must create all of the classmates' accounts use of their names


for i in `cat name`
        do
                userdel -r "$i"
                sleep 1
        done

计算账号个数脚本

#! /bin/sh


for i in `cat name`
        do
                let j=j+1
        done
echo $j

至于name文件,就是存放账号名的,一行一个


在创建好账号后,出现了问题

普通用户不能自己修改密码.
查了太多资料,虽然没帮我解决问题,但还是慢慢启发了我

解决方法很简单.

chmod u+s /usr/bin/passwd

脚本都很简单,我就不详细解释了.

如果需要做到帐号之间的隔离,即 互相没有读写权限。

可以每个帐号就为一组。

把useradd 的-g users删除就可以实现了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值