Centos configuration ShellScript

  • ShellScript
  • Write a script to add users and store it in the /shells/userAdd.sh directory
  • When a new employee joins the job, the administrator runs a script to create a company account for them.
  • Automatically assign client accounts, company emails, samba directories and permissions, website accounts, etc.

1. Set up the LDAP service

2. Installation tools

[root@storagesrv /]# yum install migrationtools  samba -y

3. Configuration services

[root@storagesrv /]# vim /usr/share/migrationtools/migrate_common.ph
$NAMINGCONTEXT{'passwd'}    = "ou=users";		#58行
$DEFAULT_MAIL_DOMAIN = "chinaskills.cn";		#71行
$DEFAULT_BASE = "dc=chinaskills,dc=cn";			#74行

4. Create script

[root@storagesrv /]# mkdir /shells
[root@storagesrv /]# vim /shells/userAdd.sh
#!/bin/bash
if
id -u $1 > /dev/null 2>&1;then
echo "user"
else
useradd $1 && tail -n 1 /etc/passwd > /root/user && \
/usr/share/migrationtools/migrate_passwd.pl /root/user > /root/user.ldif && \
ldapadd -x -w 000000 -D   "cn=Manager,dc=chinaskills,dc=cn" -f /root/user.ldif && \
printf "ChinaSkill21\nChinaSkill21\n" | smbpasswd -a -s $1
fi
[root@storagesrv /]# cd /shells/
[root@storagesrv shells]# chmod +x userAdd.sh 
[root@storagesrv shells]# ./userAdd.sh lifei
adding new entry "uid=lifei,ou=users,dc=chinaskills,dc=cn"
Added user lifei.

5. Test

[root@storagesrv /]# ldapsearch -x -b "dc=chinaskills,dc=cn" |grep "dn: uid=lifei"
dn: uid=lifei,ou=users,dc=chinaskills,dc=cn
#需要ldap和samba联动
[root@storagesrv /]# pdbedit -L |grep lifei
lifei:1008:lifei

Guess you like

Origin blog.csdn.net/LLLLLoodwd/article/details/131325472