In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to add users in batches through the shell script, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
There are two cases where for adds specified types of users and sets random passwords. One is to test the for cycle to add users in batches, and the other is to add users in batches according to the actual production environment. Write down the cases separately as follows:
Script function: batch add user1-10 users and set random 8-digit random passwords
#! / bin/bash#test add user and set passwdfor n in `seq 10`douseradd user$n;echo user$n | passwd `seradd | md5sum | cut-C1-8`done
Add users and set corresponding passwords in batch in the actual production environment
Script function: add specified users in batch in production environment, set corresponding passwords, and prohibit sudo-s and sudo-I from switching to root.
Idea: put all the usernames and passwords you want to add into an array and set a function to intercept the username and password and add the user and set the password. Finally, you can add it by calling this function with a loop.
#! / bin/bash#adduser and setpasswd userlist= (user21:123456 user22:456789 user23:876543) function adduser_setpasswd_sudo () {user= `echo $1 | awk-F:'{print $1} '`passwd= `echo $1 | awk-F:' {print $2} '``useradd-m-s / bin/bash $userecho "$user:$passwd" | chpasswdsed-I "/ ${user} / d" / etc/sudoersecho "${user} ALLNOPASSWD Groupe ! / bin/bash "> > / etc/sudoers} for n in ${userlist [@]} doadduser_setpasswd_sudo $ndone
Delete the account to be cancelled and cancel the sudo permission
#! / bin/bashcat < < EOF### delete username and cancle sudo privileges.## # EOFread-p "Please input username which you want to del:" usernameuserdel-r $usernamesed-I "/ ${username} / d" / etc/sudoers echo "Delete $username finished." Thank you for reading this article carefully. I hope the article "how to add users in bulk through shell script" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.