Sau khi cài đặt Ubuntu 22.04, chỉ có một người dùng được bạn cấu hình trong quá trình cài đặt. Và đây là administrative user. Nếu bạn muốn thêm nhiều tài khoản người dùng khác trên hệ thống, hãy cấu hình như sau.
Thêm mới user account
– Ví dụ: Thêm người dùng [bizmacvps].
ubuntu@localhost:~$ sudo adduser bizmacvps [sudo] password for ubuntu: # mật khẩu của user hiện tại Adding user `bizmacvps' ... Adding new group `bizmacvps' (1001) ... Adding new user `bizmacvps' (1001) with group `bizmacvps' ... Creating home directory `/home/bizmacvps' ... Copying files from `/etc/skel' ... New password: # đặt mật khẩu của user mới Retype new password: # comfirm mật khẩu của user mới passwd: password updated successfully Changing the user information for bizmacvps Enter the new value, or press ENTER for the default # nhập thông tin user mới (để trống tất cả nếu bạn không cần) Full Name []: bizmacvps Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] y ubuntu@localhost:~$
– Nếu bạn muốn cấp đặc quyền cho người dùng mới, hãy cấu hình như sau.
ubuntu@localhost:~$ sudo usermod -aG sudo bizmacvps ubuntu@localhost:~$ su - bizmacvps #chuyển sang user mới để test Password: To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. bizmacvps@localhost:~$
# thử chạy một lệnh yêu cầu quyền root
thanhdd@localhost:~$ sudo ls -l /root [sudo] password for bizmacvps: total 4 drwx------ 3 root root 4096 Apr 24 08:23 snap
Xóa user account
– Nếu bạn muốn xóa tài khoản người dùng, hãy cấu hình như sau.
# xóa người dùng [thanhdd] (chỉ xóa tài khoản người dùng)
ubuntu@localhost:~$ sudo deluser bizmacvps
# xóa người dùng [bizmacvps] (đã xóa tài khoản người dùng và thư mục chính của anh ta)
ubuntu@localhost:~$ sudo deluser bizmacvps --remove-home
+ Nếu lỗi như sau
ubuntu@localhost:~$ sudo deluser bizmacvps Removing user `bizmacvps' ... Warning: group `bizmacvps' has no more members. userdel: user bizmacvps is currently used by process 1881 /usr/sbin/deluser: `/sbin/userdel bizmacvps' returned error code 8. Exiting. ubuntu@localhost:~$
# cần kill porcess gây lỗi này đi
ubuntu@localhost:~$ sudo kill -9 1881 Killed
+ Nếu xóa user [bizmacvps] rồi, cần xóa thêm foler chính của user này [/home/bizmacvps]
ubuntu@localhost:$ sudo rm -rf /home/bizmacvps
Kiểm tra User accounts
– Kiểm tra
+ Kiểm tra foler chứa thư mục chính của các user
ubuntu@localhost:~$ ls -l /home total 4 drwxr-x--- 4 ubuntu ubuntu 4096 Apr 27 14:32 ubuntu
+ Kiểm tra file /etc/passwd xem còn user đã xóa không
ubuntu@localhost:~$ cat /etc/passwd Chúc các bạn thành công!