-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateaccountroot.sh
More file actions
46 lines (35 loc) · 940 Bytes
/
Copy pathcreateaccountroot.sh
File metadata and controls
46 lines (35 loc) · 940 Bytes
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
#!/bin/bash
# Run:
# chmod +x createaccountroot.sh
# ./createaccountroot.sh 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: createaccountroot.sh"
#
TYPEKEY="$1"
BITS="$2"
#
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 keys
mkdir -p /root/.ssh
if [ -f /root/.ssh/id_$TYPEKEY ]; then
rm /root/.ssh/id_$TYPEKEY
fi
if [ -f /root/.ssh/id_$TYPEKEY.pub ]; then
rm /root/.ssh/id_$TYPEKEY.pub
fi
NAMEHOST=$(uname -n)
ssh-keygen -t $TYPEKEY -b $BITS -f /root/.ssh/id_$TYPEKEY -C root@$NAMEHOST -N ""
cat /root/.ssh/id_$TYPEKEY.pub > /root/.ssh/authorized_keys
sudo systemctl reload ssh
sudo systemctl status ssh
echo "Successfully"