-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser-Management
More file actions
123 lines (105 loc) · 2.38 KB
/
Copy pathUser-Management
File metadata and controls
123 lines (105 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# User Management in Linux
## Introduction to User Management in Linux
Linux is a multi-user operating system, meaning multiple users can operate on a system simultaneously. Proper user management ensures security, controlled access, and system integrity.
Key files involved in user management:
- `/etc/passwd` – Stores user account details.
- `/etc/shadow` – Stores encrypted user passwords.
- `/etc/group` – Stores group information.
- `/etc/gshadow` – Stores secure group details.
## Creating Users in Linux
To create a new user in Linux, use:
### `useradd` Command (For most Linux distributions)
```bash
useradd username
```
This creates a user without a home directory.
To create a user with a home directory:
```bash
useradd -m username
```
To specify a shell:
```bash
useradd -s /bin/bash username
```
### `adduser` Command (For Debian-based systems)
```bash
adduser username
```
This is an interactive command that asks for a password and additional details.
## Managing User Passwords
To set or change a user’s password:
```bash
passwd username
```
### Enforcing Password Policies
- **Password expiration**: Set password expiry days
```bash
chage -M 90 username
```
- **Lock a user account**
```bash
passwd -l username
```
- **Unlock a user account**
```bash
passwd -u username
```
## Modifying Users
Modify an existing user with `usermod`:
- Change the username:
```bash
usermod -l new_username old_username
```
- Change the home directory:
```bash
usermod -d /new/home/directory -m username
```
- Change the default shell:
```bash
usermod -s /bin/zsh username
```
## Deleting Users
To remove a user but keep their home directory:
```bash
userdel username
```
To remove a user and their home directory:
```bash
userdel -r username
```
## Working with Groups
### Creating Groups
```bash
groupadd groupname
```
### Adding Users to Groups
```bash
usermod -aG groupname username
```
### Viewing Group Memberships
```bash
groups username
```
### Changing Primary Group
```bash
usermod -g new_primary_group username
```
## Sudo Access and Privilege Escalation
### Adding a User to Sudo Group
On Debian-based systems:
```bash
usermod -aG sudo username
```
On RHEL-based systems:
```bash
usermod -aG wheel username
```
### Granting Specific Commands with Sudo
Edit the sudoers file:
```bash
visudo
```
Then add:
```bash
username ALL=(ALL) NOPASSWD: /path/to/command
```