简体   繁体   English

在 Bash Shell 脚本中添加或修改用户

[英]Adding or Modifying User in Bash Shell Script

As I am trying to learn bash shell, I want to have some idea how can I add or modify the user in Bash Shell script? As I am trying to learn bash shell, I want to have some idea how can I add or modify the user in Bash Shell script?

Quick Ex:快速示例:

Adding an user:添加用户:

createuser.sh创建用户.sh

#!/bin/sh

user=$1 #first argument 
apache="www-data"
passuser=$2 # second argument
newpasswd=$(perl -e 'print crypt($ARGV[0], "S@LtStR!Ng")' $passuser)
createuser='/usr/sbin/useradd' # PATH to `useradd` package

##create and update password, then assign the apache group to the user
$createuser -d /home/$user -g $apache -m -s /bin/bash -p $newpasswd $user

Calling:来电:

root@ip-ad-2as2-ds:#./createuser.sh test test1234

This way you can control the modify-user script, just change the createuser variable to have the proper modify-user ( usermod ) package.这样您就可以控制修改用户脚本,只需将createuser变量更改为具有正确的修改用户 ( usermod ) package。

Use adduser(8) .使用adduser(8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM