Panduan cara merancang user baru di Linux, baris petunjuk ini dapat digunakan di operasi aplikasi Linux Ubuntu, Debian, Centos, Fedora, SUSE dan segala Linux varian apapun, FreeBSD serta Unix-like operating systems.
Selaku contoh disini akan menambahkan user lina
dan mia
Merancang user baru
Gunakan akun superuser (root) bagi memanajemen akun user di Linux. Ada dua petunjuk yang dapat digunakan bagi merancang user baru via command-line, yaitu useradd dan adduser, di artikel kali ini useradd
ialah cara yang saya pilih.
useradd -m lina
-m
bagi merancang direktori default di /home/lina
bagi user lina
.
* Catatan: Default direktori user berada di /home
Dengan petunjuk tersebut, user lina telah berhasil dibangun, langkah berikutnya ialah mengatur password (kata sandi) bagi user lina.
passwd lina
Hasilnya
Enter new UNIX password:
Retype new UNIX password:
Kemudian masukkan password bagi user lina.
Tambah user baru lainya, misalnya mia
useradd -m mia
passwd mia
Kalau menginginkan direktori yang berbeda tambahkan opsi -d
useradd mia -d /var/www/html
Atau merancang user tanpa direktori dengan opsi -M
useradd -M mia
Catatan:
- Gunakan petunjuk
usermod
bagi mengganti home directory user, contoh:usermod -d /direktori/baru mia
Melihat informasi user, dengan petunjuk berikut
cat /etc/passwd | grep mia
Hasilnya
mia:x:5001:5001::/home/mia:
Menambahkan user tanpa akses login shell
useradd -s /sbin/nologin mia
Menghapus user
userdel mia
Menghapus user sekaligus home directory dan mail spool directory
userdel -r mia
Menambahkan user ke group sudo
Bagi Debian/Ubuntu
usermod -aG sudo mia
bagi CentOS
usermod -aG wheel mia
Opsi lainya dapat dilihat via
useradd -help
Hasilnya
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new account
-G, --groups GROUPS list of supplementary groups of the new account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as the user
-o, --non-unique allow to create users with duplicate (non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
--extrausers Use the extra users database
Cara login user lain (beralih) pada satu terminal.
su - mia
su
artinya swith user
Cara keluar
exit
Selamat mencoba kawan.
Sumber https://idnetter.com