Linux/User Management: Difference between revisions
Brodriguez (talk | contribs) (Add "removing user" section) |
Brodriguez (talk | contribs) m (Brodriguez moved page Linux User Management to Linux/User Management: Clean url with subpages) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Terminal commands to manage user accounts in linux. | Terminal commands to manage user accounts in linux. | ||
== Creating a New User == | == User Management == | ||
=== Viewing Users === | |||
<code>cat /etc/passwd</code> | |||
=== Accessing Users === | |||
It's possible to take control of other user accounts from terminal, without having to log out and back in. | |||
Access sudo account: | |||
{{ note | This will only work if you have sudo/root permissions from the current account. }} | |||
* <code>sudo su</code> | |||
Access another standard user account: | |||
* <code>su <user_name></code> | |||
=== Creating a New User === | |||
The most basic implementation is: | The most basic implementation is: | ||
* <code>useradd <user_name></code> | * <code>useradd <user_name></code> | ||
From there, you can add argument options such as: | From there, you can add argument options such as: | ||
* <code>-m</code> or <code>--create-home</code> - Creates a home directory for user. | |||
* <code>-M</code> or <code>--no-create-home</code> - Skips creating a home directory for user. | * <code>-M</code> or <code>--no-create-home</code> - Skips creating a home directory for user. | ||
* <code>-U</code> or <code>--user-group</code> - Creates a new group with the same name as user. | |||
* <code>-N</code> or <code>--no-user-group</code> - Skips creating a group with the same name as user. | * <code>-N</code> or <code>--no-user-group</code> - Skips creating a group with the same name as user. | ||
* <code>-G</code> or <code>--groups</code> - Set additional user groups user is part of, during user creation. | * <code>-G</code> or <code>--groups</code> - Set additional user groups user is part of, during user creation. | ||
Line 15: | Line 32: | ||
This creates a user called "my_user" that is associated with groups "admins", "webadmin", and "developers". | This creates a user called "my_user" that is associated with groups "admins", "webadmin", and "developers". | ||
=== Updating User Password === | |||
== Updating User Password == | |||
Update password for current account: | Update password for current account: | ||
* <code>passwd</code> | * <code>passwd</code> | ||
Line 22: | Line 38: | ||
Update password for another user account: | Update password for another user account: | ||
* <code>passwd <user_name></code> | * <code>passwd <user_name></code> | ||
=== Removing User Account Properties === | |||
Remove user home folder: | |||
* <code>userdel -r <user_name></code> | |||
Remove user account entirely: | |||
* <code>userdel <user_name></code> | |||
== Group Management == | == Group Management == | ||
=== Groups and Group Membership === | === Viewing Groups and Group Membership === | ||
View check all existing groups: | View check all existing groups: | ||
* <code>cat /etc/group</code> | * <code>cat /etc/group</code> | ||
Line 46: | Line 69: | ||
Remove user from group: | Remove user from group: | ||
* <code>gpasswd -d <user_name> <group_name></code> | * <code>gpasswd -d <user_name> <group_name></code> | ||
Latest revision as of 08:53, 15 May 2020
Terminal commands to manage user accounts in linux.
User Management
Viewing Users
cat /etc/passwd
Accessing Users
It's possible to take control of other user accounts from terminal, without having to log out and back in.
Access sudo account:
sudo su
Access another standard user account:
su <user_name>
Creating a New User
The most basic implementation is:
useradd <user_name>
From there, you can add argument options such as:
-m
or--create-home
- Creates a home directory for user.-M
or--no-create-home
- Skips creating a home directory for user.-U
or--user-group
- Creates a new group with the same name as user.-N
or--no-user-group
- Skips creating a group with the same name as user.-G
or--groups
- Set additional user groups user is part of, during user creation.-r
or--system
- Create a "system" account. Aka, a user with no password, no home directory, and is unable to log in.
Example:
useradd -G admins,webadmin,developers my_user
This creates a user called "my_user" that is associated with groups "admins", "webadmin", and "developers".
Updating User Password
Update password for current account:
passwd
Update password for another user account:
passwd <user_name>
Removing User Account Properties
Remove user home folder:
userdel -r <user_name>
Remove user account entirely:
userdel <user_name>
Group Management
Viewing Groups and Group Membership
View check all existing groups:
cat /etc/group
View all members of a group:
getent group <group_name>
View all groups for given user:
groups <user_name>
Adding and Removing User Groups
Add current user to group:
groupadd <group_name>
Add given user to group:
usermod -a -G <group_name> <user_name>
Remove user from group:
gpasswd -d <user_name> <group_name>