-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddApiMethod
More file actions
35 lines (28 loc) · 904 Bytes
/
Copy pathaddApiMethod
File metadata and controls
35 lines (28 loc) · 904 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
#!/bin/bash
set -euo pipefail
# addApiMethod — Register a new API method as a system user.
# Usage: addApiMethod <method_name>
#
# Creates a system user whose login shell is the method script at
# /opt/sshAsApi/<method_name>. The user is added to the sshapi group
# (gid 666) and public-key authentication is configured by default.
if [ $# -ne 1 ]; then
echo "Usage: addApiMethod <method_name>"
exit 1
fi
METHOD_NAME="$1"
METHOD_PATH="/opt/sshAsApi/${METHOD_NAME}"
if [ ! -f "${METHOD_PATH}" ]; then
echo "Error: method script not found at ${METHOD_PATH}"
exit 1
fi
adduser --system \
--home "/home/${METHOD_NAME}" \
--gid 666 \
--shell "${METHOD_PATH}" \
--disabled-password \
"${METHOD_NAME}"
chown "${METHOD_NAME}" "${METHOD_PATH}"
chmod 500 "${METHOD_PATH}"
# Set public-key authentication as default
/root/commands/authConfig "${METHOD_NAME}" PUBLIC_KEY