Tạo tài khoản user non-root trên Ubuntu (sudo-enable)

1 — Đăng nhập vào server

SSH in to your server as the root user:

Truy cập vào server bằng tài khoản root (via ssh command)

ssh root@your_server_ip_address

2 — Tạo tài khoản mới

Sử dụng lệnh adduser để thêm tài khoản mới vào hệ thống:

adduser testuser

Chú ý thay thế testuser bằng tên tài khoản mà bạn muốn. Tiếp theo bạn sẽ được yêu cầu tạo và xác nhận mật khẩu cho tài khoản:

OutputEnter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Tiếp theo bạn sẽ được hỏi một số thông tin liên quan đến tài khoản muốn tạo, có thể sử dụng giá trị mặc định (để trống tất cả thông tin):

OutputChanging the user information for testuser
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n]

3 — Thêm tài khoản vào Group sudo

Use the usermod command to add the user to the sudo group:

Sử dụng lệnh usermod để thêm user vào group sudo

usermod -aG sudo testuser

4 — Kiểm tra quyền truy cập sudo

Sử dụng lệnh su để chuyển sang user vừa tạo:

su - testuser

Với user mới, xác nhận bạn có thể sử dụng lệnh sudo bằng cách chạy các câu lệnh mà yêu cầu quyền superuser:

sudo command_to_run

Ví dụ:

sudo ls -la /root
Output:[sudo] password for testuser:

vinhvd

Hello there! 👋 I'm Vinh.