2019-01-04 16:38:20 +01:00
|
|
|
#!/bin/sh
|
2019-01-07 14:47:05 +01:00
|
|
|
#
|
|
|
|
# Set or get ssh pubic key of <jailname>
|
|
|
|
# Usage: key <jailname> [<keyfile>]
|
|
|
|
#
|
2019-01-04 16:38:20 +01:00
|
|
|
|
2020-04-02 13:44:13 +02:00
|
|
|
# shellcheck source=./includes
|
2020-04-02 00:31:57 +02:00
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
2019-01-04 16:38:20 +01:00
|
|
|
|
2020-04-02 13:44:13 +02:00
|
|
|
jail_name="${1:?}"
|
2019-01-04 16:38:20 +01:00
|
|
|
keyfile="${2:-}"
|
2020-04-02 01:07:12 +02:00
|
|
|
|
|
|
|
if [ ! -n "${jail_name}" ]; then
|
2020-10-07 20:50:17 +02:00
|
|
|
show_help && exit 1
|
2019-01-07 14:47:05 +01:00
|
|
|
fi
|
2020-04-02 01:07:12 +02:00
|
|
|
jail_path=$(jail_path "${jail_name}")
|
|
|
|
|
2020-05-01 09:51:09 +02:00
|
|
|
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
|
2019-01-04 16:38:20 +01:00
|
|
|
|
|
|
|
if [ -z "${keyfile}" ]; then
|
2020-04-02 01:07:12 +02:00
|
|
|
if [ -f "${jail_path}/${AUTHORIZED_KEYS}" ]; then
|
|
|
|
cat "${jail_path}/${AUTHORIZED_KEYS}"
|
2019-01-04 16:38:20 +01:00
|
|
|
fi
|
|
|
|
else
|
2020-04-20 08:29:21 +02:00
|
|
|
test -r "${keyfile}" || error "SSH key \`${keyfile}' for jail \`${jail_name}' is missing or is not readable."
|
2020-04-02 01:07:12 +02:00
|
|
|
cat "${keyfile}" > "${jail_path}/${AUTHORIZED_KEYS}"
|
|
|
|
chmod 600 "${jail_path}/${AUTHORIZED_KEYS}"
|
2020-04-20 08:29:21 +02:00
|
|
|
notice "Update SSH key \`${keyfile}' for jail \`${jail_name}' : OK"
|
2019-01-04 16:38:20 +01:00
|
|
|
fi
|