[英]Add bash script on linux to create users
I ask for your help to create a script to create a user and a password on 1 click 我需要您的帮助,以创建脚本来创建用户和密码,单击1次
useradd client1 -M -s /bin/false
passwd client1
To have for instance a new user with: 例如拥有一个新用户:
login: client1 password: test 登录名:client1密码:test
Is it possible ? 可能吗 ? and if it is, how please ? 如果是,请如何?
应该这样做:
adduser client1 -p $(perl -e'print crypt("test", "aa")')
man useradd will give you hints to do this and I believe this is how: man useradd将为您提供执行此操作的提示,我相信这是这样的:
useradd [username] -d /path_to_home_directory -p [encrypted_password] useradd [用户名] -d / path_to_home_directory -p [encrypted_password]
now, VERY IMPORTANT, the documentation for useradd says that the -p parameter expects the password ENCRYPTED as returned by crypt(7); 现在,非常重要,useradd的文档说-p参数期望由crypt(7)返回的密码为ENCRYPTED; therefore, what you need to do is create a sample user with password "test" for example, then open up /etc/shadow and copy and paste the password from the file and use it on your script. 因此,您需要做的是创建一个示例用户,其密码为“ test”,然后打开/ etc / shadow并从文件中复制并粘贴密码,然后在脚本中使用它。
Suppose that "test" encrypted in /etc/shadow appears as "zxs1@431sa" your final script should be: 假设在/ etc / shadow中加密的“测试”显示为“ zxs1 @ 431sa”,您的最终脚本应为:
useradd [username] -d /path_to_home_dir -p zxs1@431sa [enter] useradd [用户名] -d / path_to_home_dir -p zxs1 @ 431sa [输入]
That should do it, I think. 我认为应该这样做。
References: http://linux.die.net/man/8/useradd 参考: http : //linux.die.net/man/8/useradd
Ok I find it : 好的,我找到了:
First Script create user: (add_user.sh) 第一个脚本创建用户:(add_user.sh)
#!/bin/sh
useradd $1 -M -s /bin/false
Second one create a password or change it: 第二个创建或更改密码:
#!/bin/sh
echo "$1:$2" | chpasswd
Do you know how i can call this script from php file ? 您知道我如何从php文件中调用此脚本吗?
<?php
Execution (add_user.sh) ?
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.