Linuxでユーザーを追加してグループに割り当てるスクリプト

Linuxでユーザーを追加してグループに割り当てるスクリプト

Linuxに初めて触れる私は、次のような要件があることを行う必要があります(これを自動化するスクリプトを作成したい)。

  1. Linuxユーザーの作成(SUDOを除く)

  2. 各生成のパスワード(各生成のファイルにパスワードを書き込む)

  3. aws cliの正しいBINパスを設定してください。

  4. すべてのユーザーを「ユーザー」グループに追加

これが私が今まで持っているのですが、3段階と4段階が混乱します。どんな助けでも大変感謝します!

//execute the Script using a bash shell
#!/bin/bash

//location of the txt file of usernames
userfile=/tmp/userlist 

//extracting usernames from the file one-by-one
username=$(cat /tmp/userlist | tr 'A-Z'  'a-z')

//defining the default password 
password=$username@123

//running loop  to add users
for user in $username
do
       //adding users '$user' is a variable that changes
       // usernames accordingly in txt file.
       useradd $user
       echo $password | passwd --stdin $user
done

ベストアンサー1

おすすめ記事