-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateaccount.sh
More file actions
64 lines (49 loc) · 1.44 KB
/
createaccount.sh
File metadata and controls
64 lines (49 loc) · 1.44 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
#!/bin/bash
# Run:
# chmod +x createaccount.sh
# ./createaccount.sh debugvscode sudo ed25519 256
# https://manpages.ubuntu.com/manpages/jammy/man1/ssh-keygen.1.html
# TYPEKEY = dsa | ecdsa | ed25519 | rsa
# BITS = 256 | 384 | 521 | 1024 | 2048 | 3072 | 4096
set -e #Exit immediately if a comman returns a non-zero status
echo "Run: createaccount.sh"
#
NEWUSERNAME="$1"
GROUPUSER="$2"
TYPEKEY="$3"
BITS="$4"
#
if [ -z $NEWUSERNAME ]; then
echo "Error: NEWUSERNAME not specified"
exit 1;
fi
if [ -z $GROUPUSER ]; then
echo "Error: GROUPUSER not specified"
exit 2;
fi
if [ -z $TYPEKEY ]; then
echo "Error: TYPEKEY not specified"
exit 3;
fi
if [ -z $BITS ]; then
echo "Error: BITS not specified"
exit 4;
fi
#create user
id -u $NEWUSERNAME &>/dev/null || sudo adduser --disabled-password --gecos "" $NEWUSERNAME
sudo usermod -aG $GROUPUSER $NEWUSERNAME
sudo echo "debugvscode ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/debugvscode
#create keys
mkdir -p /home/$NEWUSERNAME/.ssh
if [ -f /home/$NEWUSERNAME/.ssh/id_$TYPEKEY ]; then
rm /home/$NEWUSERNAME/.ssh/id_$TYPEKEY
fi
if [ -f /home/$NEWUSERNAME/.ssh/id_$TYPEKEY.pub ]; then
rm /home/$NEWUSERNAME/.ssh/id_$TYPEKEY.pub
fi
NAMEHOST=$(uname -n)
ssh-keygen -t $TYPEKEY -b $BITS -f /home/$NEWUSERNAME/.ssh/id_$TYPEKEY -C $NEWUSERNAME@$NAMEHOST -N ""
cat /home/$NEWUSERNAME/.ssh/id_$TYPEKEY.pub > /home/$NEWUSERNAME/.ssh/authorized_keys
sudo systemctl reload ssh
sudo systemctl status ssh
echo "Successfully"