-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuser_add.sh
More file actions
41 lines (31 loc) · 1.05 KB
/
user_add.sh
File metadata and controls
41 lines (31 loc) · 1.05 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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
read -rp "Enter username: " username
if ! id -u "$username" &>/dev/null; then
useradd -m -d "/home/$username" "$username"
echo "User $username created."
read -rsp "Enter password for $username: " password
echo
echo "$username:$password" | chpasswd
chage -d 0 "$username"
mkdir -p "/home/$username/.ssh"
chmod 700 "/home/$username/.ssh"
chown -R "$username:$username" "/home/$username"
echo -e "\nAvailable keys in /home/server/.keys/:"
ls -1 /home/server/.keys/
while true; do
read -rp "Enter filename to copy (or type 0 to exit): " filename
[[ "$filename" == "0" ]] && break
if [[ -f "/home/server/.keys/$filename" ]]; then
cp -v "/home/server/.keys/$filename" "/home/$username/.ssh/"
else
echo "File not found: $filename"
fi
done
chown -R "$username:$username" "/home/$username/.ssh"
echo "SSH setup complete for $username."
else
echo "User '$username' already exists. Exiting."
exit 1
fi