Managing Users in Ubuntu

User management is an essential part of maintaining a secure and organized Ubuntu system. This guide provides you with various commands and procedures for managing users on your Ubuntu system.

Listing All Users

To list all users on your system, you can use the following command:

1
cut -d: -f1 /etc/passwd

Adding a New User

You can add a new user using either of the following commands:

1
sudo adduser *new_username*

or

1
sudo useradd *new_username*

For more information on the difference between adduser and useradd, refer to the section What is the difference between adduser and useradd?.

Removing a User

To remove or delete a user, follow these steps:

  1. Delete the user account:
1
sudo userdel *username*
  1. Optionally, you may want to delete the user’s home directory:
1
sudo rm -r /home/*username*

Please exercise caution when using the rm command, as it will permanently delete the user’s files and directories.

Modifying User Attributes

Changing the Username

To change a user’s username, you can use the usermod command:

1
sudo usermod -l *new_username* *old_username*

Changing the Password

To change a user’s password, use the passwd command:

1
sudo passwd *username*

Changing the Shell

To change the default shell for a user, utilize the chsh command:

1
sudo chsh *username*

Changing User Details

To modify a user’s details, such as their real name, you can use the chfn command:

1
sudo chfn *username*

Additional Resources

For more detailed information and options regarding user management, consult the manual pages for the relevant commands. Use the following commands to access the manual pages:

  • man adduser: Manual for the adduser command.
  • man useradd: Manual for the useradd command.
  • man userdel: Manual for the userdel command.
  • And more: You can explore other user management commands by using the man command followed by the command name.

Proper user management is crucial for system security and organization. Be cautious when making changes to user accounts, especially when deleting user data. Always have up-to-date backups and consider the implications of each action.

0%