2022-04-24 15:01:06 +02:00
|
|
|
---
|
2023-02-23 14:48:51 +01:00
|
|
|
title: "Users and Groups"
|
2022-11-19 15:25:20 +01:00
|
|
|
visible: true
|
2022-04-24 15:01:06 +02:00
|
|
|
---
|
|
|
|
|
2022-06-06 18:28:43 +02:00
|
|
|
[toc]
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-06-06 18:28:43 +02:00
|
|
|
## Users
|
2022-04-24 15:01:06 +02:00
|
|
|
|
2023-02-23 14:48:51 +01:00
|
|
|
Check users by looking at `/etc/passwd`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
### Add users
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-04-24 15:01:06 +02:00
|
|
|
Basic usage:
|
2023-02-23 14:48:51 +01:00
|
|
|
`# useradd -m (user)`
|
|
|
|
|
|
|
|
Important options:
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
login name -> by default
|
|
|
|
group -> -G //separate multiple by commas: group1,group2
|
|
|
|
with home dir -> -m
|
|
|
|
shell -> -s
|
|
|
|
full name -> -c
|
|
|
|
```
|
|
|
|
|
|
|
|
Example more complicated usage:
|
2023-02-23 14:48:51 +01:00
|
|
|
`# useradd -m -c "Bruno Huber" -s /bin/bash -G sudo,systemd-journal bruhub`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
2022-07-07 08:54:39 +02:00
|
|
|
### Remove user
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-07-07 08:54:39 +02:00
|
|
|
The command `userdel` can be used to remove users from a system.
|
|
|
|
Using it with the `-r` additionally deletes the user home directory and mail spool.
|
2023-02-23 14:48:51 +01:00
|
|
|
`# userdel -r (user)`
|
2022-07-07 08:54:39 +02:00
|
|
|
|
2022-04-24 15:01:06 +02:00
|
|
|
### Add user to groups
|
2023-02-23 14:48:51 +01:00
|
|
|
|
2022-04-24 15:01:06 +02:00
|
|
|
Add user to more groups:
|
2023-02-23 14:48:51 +01:00
|
|
|
`# usermod -a -G (group1),(group2) (user)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
Alternative command:
|
2023-02-23 14:48:51 +01:00
|
|
|
`# gpasswd -a (user) (group)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
### Remove user from group
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
`# gpasswd -d (user) (group)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
## Groups
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
Check a user's groups with `id (user)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
### Create group
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
`# groupadd (group)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
### Rename group
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
`# groupmod -n (new_group) (old_group)`
|
2022-04-24 15:01:06 +02:00
|
|
|
|
|
|
|
### Delete group
|
2023-02-23 14:48:51 +01:00
|
|
|
|
|
|
|
`# groupdel (group)`
|