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

Dari Catatan Pak Samsul
Loncat ke navigasi Loncat ke pencarian
kTidak ada ringkasan suntingan
kTidak ada ringkasan suntingan
 
(3 revisi perantara oleh pengguna yang sama tidak ditampilkan)
Baris 1: Baris 1:
  for i in "$@"; do
  for i in "$@"; do
  echo creating user "$i"
echo creating user "$i"
   sudo adduser --gecos "" --disable-password $in
   sudo adduser --gecos "" --disable-password $i
  echo add user to sudo group
echo add user to sudo group
   sudo usermod -aG sudo $i
   sudo usermod -aG sudo $i
  echo creating ssh folder and authorized_keys
  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 'mkdir -p /home/"$0"/.ssh' $i
   sudo -H -u $i bash -c 'chmod 700 /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 -H -u $i bash -c 'touch 600 /home/"$0"/.ssh/authorized_keys' $i
  echo buat folder public_html dan mkdir
  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 'mkdir -p /home/public_html' $i
Baris 17: Baris 15:
  done
  done


Kemdian simpan dengan nama createuser.sh
Kemudian simpan dengan nama '''createuser.sh'''


Untuk menjalankan silahkan ketik
Untuk menjalankan silahkan ketik


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

Revisi terkini sejak 15 Januari 2022 10.56

for i in "$@"; do
echo creating user "$i"
 sudo adduser --gecos "" --disable-password $i
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

Kemudian simpan dengan nama createuser.sh

Untuk menjalankan silahkan ketik

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