fix small bugs and add host keys to sshkeys

This commit is contained in:
2021-12-30 03:32:06 +01:00
parent 2b366fbb15
commit 893be48e01
2 changed files with 29 additions and 7 deletions
+23 -5
View File
@@ -5,20 +5,27 @@ touch "/.ssh/authorized_keys"
# Add User
sh -c "echo '$USER ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
addgroup -g "$GID" "$USER"
echo "ADD USER: $USER WITH UID: $UID"
adduser \
--disabled-password \
--gecos "" \
--home "/" \
--ingroup "$USER" \
--uid "$UID" \
"$USER"
echo "$USER:*" | chpasswd
echo "ADD GROUP: $USER WITH GID: $GID"
addgroup -g "$GID" "$USER"
mkdir -p /sshkeys/clients
mkdir -p /sshkeys/host
chown -R "$USER":"$USER" "/sshkeys"
# Add SSH Keys to authorized_keys
for key in /sshkeys/*.pub; do
FILES=$(ls -1 /sshkeys/clients)
for key in $FILES; do
echo "Adding SSH-Key $key"
cat "$key" >> "/.ssh/authorized_keys"
cat "/sshkeys/clients/$key" >> "/.ssh/authorized_keys"
done
echo "" >> "/.ssh/authorized_keys"
@@ -28,5 +35,16 @@ chmod 700 "/.ssh"
chmod 600 "/.ssh/authorized_keys"
# Generate SSH-Keys
ssh-keygen -A
if [ ! -f "/sshkeys/host/ssh_host_rsa_key" ]; then
ssh-keygen -t rsa -b 4096 -f "/sshkeys/host/ssh_host_rsa_key" -N ""
fi
if [ ! -f "/sshkeys/host/ssh_host_ecdsa_key" ]; then
ssh-keygen -t ecdsa -b 521 -f "/sshkeys/host/ssh_host_ecdsa_key" -N ""
fi
if [ ! -f "/sshkeys/host/ssh_host_ed25519_key" ]; then
ssh-keygen -t ed25519 -b 521 -f "/sshkeys/host/ssh_host_ed25519_key" -N ""
fi
chown -R "$USER":"$USER" "/sshkeys/host"
exec /usr/sbin/sshd -D -e "$@"