TDCTF Academy Logo TDCTF ACADEMY

User Management

File Konfigurasi User

Linux menyimpan informasi user dalam tiga file teks utama:

/etc/passwd

Setiap baris mewakili satu user dengan format:

username:password:UID:GID:comment:home_dir:shell

Contoh:

alice:x:1001:1001:Alice Johnson:/home/alice:/bin/bash
  • x - password disimpan di /etc/shadow (shadow password)
  • UID 0 = root, UID 1-999 = system user, UID 1000+ = regular user
  • Shell /usr/sbin/nologin untuk user yang tidak boleh login

/etc/shadow

Menyimpan password terenkripsi dan kebijakan aging:

alice:$y$j9T$abc...:19876:0:99999:7:30::
Kolom Makna
Hash password Enkripsi (SHA-512, yescrypt, bcrypt)
19876 Hari terakhir password diubah (epoch days since 1970-01-01)
0 Minimum hari sebelum password bisa diubah
99999 Maksimum hari password berlaku
7 Warning sebelum expired

/etc/group

sudo:x:27:alice,bob
  • Group ID (GID) untuk group sudo adalah 27
  • Anggota: alice, bob

Manajemen User

Membuat user:

sudo useradd -m -s /bin/bash -c "Alice Johnson" alice
sudo passwd alice # Set password
Opsi useradd Fungsi
-m Buat home directory
-s Tentukan shell
-c Comment / full name
-G Tambahkan ke secondary group
-u Tentukan UID manual

Memodifikasi user:

sudo usermod -s /bin/zsh alice # Ganti shell
sudo usermod -aG sudo alice # Tambah ke group sudo (append)
sudo usermod -l alice2 alice # Ganti username
sudo usermod -L alice # Lock akun
sudo usermod -U alice # Unlock akun

Menghapus user:

sudo userdel alice # Hapus user, home tetap
sudo userdel -r alice # Hapus user + home + mail spool

Manajemen Group

sudo groupadd developers # Buat group baru
sudo groupmod -n devs developers # Rename group
sudo groupdel devs # Hapus group
sudo gpasswd -a alice developers # Tambah user ke group
sudo gpasswd -d alice developers # Hapus user dari group
groups alice # Lihat group user

Password Aging dengan chage

chage (change age) mengatur kebijakan password:

sudo chage -l alice # Lihat info aging
sudo chage -M 90 alice # Password expired setelah 90 hari
sudo chage -m 7 alice # Min 7 hari sebelum ganti password
sudo chage -W 14 alice # Warning 14 hari sebelum expired
sudo chage -E 2026-12-31 alice # Akun expired tanggal tertentu
sudo chage -d 0 alice # Paksa ganti password saat login

Skel Directory

Saat user baru dibuat dengan -m, file dari /etc/skel/ di-copy ke home directory user baru.

ls -la /etc/skel/ # Lihat template default
# Contoh isi: .bashrc, .profile, .bash_logout

Administrator bisa menambahkan file ke /etc/skel/ - misalnya .bash_aliases dengan alias umum:

# /etc/skel/.bash_aliases
alias ll='ls -la'
alias ..='cd ..'
alias df='df -h'

UID dan GID

  • UID 0 - root, memiliki akses penuh ke sistem
  • UID 1-999 - system user (daemon, sshd, www-data)
  • UID 1000+ - regular user
  • GID mengikuti pola yang sama

Cek UID/GID: id alice atau cat /etc/passwd | grep alice.

Superuser: Root dan Sudo

Root adalah user dengan UID 0 yang memiliki akses tak terbatas. Best practice: jangan login sebagai root langsung. Gunakan sudo.

Sudo memberi akses administratif terbatas:

sudo -l # Lihat perintah apa yang boleh dijalankan user
sudo -u www-data cat /var/log/nginx/access.log # Jalankan sebagai user lain

Konfigurasi sudo di /etc/sudoers:

alice ALL=(ALL:ALL) ALL # Alice bisa sudo semua perintah
bob ALL=(ALL) /usr/bin/systemctl # Bob hanya bisa systemctl
%admin ALL=(ALL) ALL # Semua anggota group admin

Edit dengan visudo (bukan editor manual) untuk mencegah syntax error yang bisa mengunci akses sudo.

Tips keamanan: batasi akses sudo seminimal mungkin (principle of least privilege), aktifkan logging sudo, dan nonaktifkan login root via SSH dengan PermitRootLogin no di /etc/ssh/sshd_config.

PADA HALAMAN INI