Membuat user otomatis dengan Scripting bash shell pada Debian: Perbedaan antara revisi

Dari Catatan Pak Samsul
Loncat ke navigasi Loncat ke pencarian
(←Membuat halaman berisi 'for i in "$@"; do echo creating user "$i" sudo adduser --gecos "" --disable-password $in echo add user to sudo group sudo usermod -aG sudo $i echo creating ssh fo...')
 
kTidak ada ringkasan suntingan
Baris 1: Baris 1:
for i in "$@"; do
for i in "$@"; do
  echo creating user "$i"
  sudo adduser --gecos "" --disable-password $in
  echo add user to sudo group
  sudo usermod -aG sudo $i


echo creating user "$i"
echo creating ssh folder and authorized_keys
  sudo -H -u $i bash -c 'mkdir -p /home/"$0"/.ssh' $i
  sudo -H -u $i bash -c 'chmod 700 /home/"$0"/.ssh/' $i
  sudo -H -u $i bash -c 'touch 600 /home/"$0"/.ssh/authorized_keys' $i


sudo adduser --gecos "" --disable-password $in
echo buat folder public_html dan mkdir
  sudo -H -u $i bash -c 'mkdir -p /home/public_html' $i
  sudo -H -u $i bash -c 'chmod 700 /home/"$0"/public_html' $i
  sudo -H -u $i bash -c 'mkdir -p /home/"$0"/mail_dir' $i
  sudo -H -u $i bash -c 'chmod 700 /home/"$0"/mail_dir' $i
done


echo add user to sudo group
Kemdian simpan dengan nama createuser.sh


sudo usermod -aG sudo $i
Untuk menjalankan silahkan ketik


echo creating ssh folder and authorized_keys
$/home/samsul/.createuser.sh user1 user2 user3 user4 user5
 
sudo -H -u $i bash -c 'mkdir -p /home/"$0"/.ssh' $i
 
sudo -H -u $i bash -c 'chmod 700 /home/"$0"/.ssh/' $i
 
sudo -H -u $i bash -c 'touch 600 /home/"$0"/.ssh/authorized_keys' $i
 
echo buat folder public_html dan mkdir
 
sudo -H -u $i bash -c 'mkdir -p /home/public_html' $i
 
sudo -H -u $i bash -c 'chmod 700 /home/"$0"/public_html' $i
 
sudo -H -u $i bash -c 'mkdir -p /home/"$0"/mail_dir' $i
 
sudo -H -u $i bash -c 'chmod 700 /home/"$0"/mail_dir' $i
 
done

Revisi per 15 Januari 2022 10.53

for i in "$@"; do
 echo creating user "$i"
 sudo adduser --gecos "" --disable-password $in
 echo add user to sudo group
 sudo usermod -aG sudo $i
echo creating ssh folder and authorized_keys
 sudo -H -u $i bash -c 'mkdir -p /home/"$0"/.ssh' $i
 sudo -H -u $i bash -c 'chmod 700 /home/"$0"/.ssh/' $i
 sudo -H -u $i bash -c 'touch 600 /home/"$0"/.ssh/authorized_keys' $i
echo buat folder public_html dan mkdir
 sudo -H -u $i bash -c 'mkdir -p /home/public_html' $i
 sudo -H -u $i bash -c 'chmod 700 /home/"$0"/public_html' $i
 sudo -H -u $i bash -c 'mkdir -p /home/"$0"/mail_dir' $i
 sudo -H -u $i bash -c 'chmod 700 /home/"$0"/mail_dir' $i
done

Kemdian simpan dengan nama createuser.sh

Untuk menjalankan silahkan ketik

$/home/samsul/.createuser.sh user1 user2 user3 user4 user5