forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-user-ssh-key
More file actions
65 lines (52 loc) · 1.66 KB
/
v-add-user-ssh-key
File metadata and controls
65 lines (52 loc) · 1.66 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
#!/bin/bash
# info: add ssh key
# options: USER key
#
# Function check if $user/.ssh/authorized_keys exists and create it
# After that it append the new key(s)
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
key=$2
# Includes
source $HESTIA/func/main.sh
source $HESTIA/conf/hestia.conf
# Additional argument formatting
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Reading user values
source $USER_DATA/user.conf
#check if file exits
AUTHKEY_FILE=$HOMEDIR/$user/.ssh/authorized_keys
if [ ! -f "$AUTHKEY_FILE" ]; then
touch "$AUTHKEY_FILE"
chown ${user}: "${AUTHKEY_FILE}"
fi
TEMP=$(mktemp)
echo "$key" >> "$TEMP"
ssh-keygen -l -f "$TEMP"
if [ ! $? -eq 0 ]; then
rm "$TEMP"
exit
fi
rm "$TEMP"
#append key to file
echo "$key" >> "$AUTHKEY_FILE"
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
log_history "added ssh-key $user"
log_event "$OK" "$ARGUMENTS"
exit