added automatic force of ssh key login
added script for loading ssh keys from git
This commit is contained in:
parent
c443d8e0fd
commit
158d369a5b
2 changed files with 47 additions and 4 deletions
15
install.sh
15
install.sh
|
@ -6,9 +6,16 @@ if [[ -z "$idk" ]]; then
|
|||
echo 'alias sudo=""' >> ~/.bashrc
|
||||
fi
|
||||
|
||||
apt install -y caddy
|
||||
CONFIG_FILE="/etc/ssh/sshd_config"
|
||||
|
||||
# Upraví konfiguraci SSH pro povolení pouze přihlašování pomocí klíčů
|
||||
sed -i 's/^#\?\(PasswordAuthentication\) .*/\1 no/' "$CONFIG_FILE"
|
||||
sed -i 's/^#\?\(PermitRootLogin\) .*/\1 prohibit-password/' "$CONFIG_FILE"
|
||||
sed -i 's/^#\?\(PubkeyAuthentication\) .*/\1 yes/' "$CONFIG_FILE"
|
||||
|
||||
# Restart SSH, aby se změny projevily
|
||||
systemctl restart sshd
|
||||
|
||||
echo "SSH je nyní nastaveno pouze pro přihlašování pomocí klíčů."
|
||||
|
||||
cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak
|
||||
|
||||
cp ./config/Caddyfile /etc/caddy/Caddyfile
|
||||
systemctl reload caddy
|
||||
|
|
36
update-ssh-keys.sh
Normal file
36
update-ssh-keys.sh
Normal file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
KEYS_DIR="/root/ssh-keys"
|
||||
AUTHORIZED_KEYS="/root/.ssh/authorized_keys"
|
||||
else
|
||||
if [ -z "$1" ]; then
|
||||
USER='whoami'
|
||||
else
|
||||
USER='$1'
|
||||
fi
|
||||
KEYS_DIR="/home/${USER}/ssh-keys"
|
||||
AUTHORIZED_KEYS="/home/${USER}/.ssh/authorized_keys"
|
||||
fi
|
||||
|
||||
# Git repo
|
||||
GIT_REPO="https://git.chillplace.beer/jirka1324/ssh-keys.git"
|
||||
|
||||
# Logování
|
||||
LOG_FILE="/var/log/update-ssh-keys.log"
|
||||
|
||||
# Pokud repo neexistuje, naklonovat
|
||||
if [ ! -d "$KEYS_DIR" ]; then
|
||||
git clone "$GIT_REPO" "$KEYS_DIR" >> "$LOG_FILE" 2>&1
|
||||
fi
|
||||
|
||||
# Stáhnout nové změny
|
||||
cd "$KEYS_DIR" || exit
|
||||
git pull origin main >> "$LOG_FILE" 2>&1
|
||||
|
||||
# Zkopírovat do ~/.ssh
|
||||
cp "$KEYS_DIR/authorized_keys" "$AUTHORIZED_KEYS"
|
||||
chown "$USER:$USER" "$AUTHORIZED_KEYS"
|
||||
chmod 600 "$AUTHORIZED_KEYS"
|
||||
|
||||
echo "Klíče aktualizovány: $(date)" >> "$LOG_FILE"
|
||||
|
Loading…
Reference in a new issue