Files
local_machine/docs/old_mac/scripts/setup-ssh-fedora.sh

71 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Fedora: включить SSH и подготовить удалённый доступ.
# sudo bash setup-ssh-fedora.sh [имя_пользователя]
set -euo pipefail
USER_NAME="${1:-${SUDO_USER:-$USER}}"
SSH_DIR="/home/$USER_NAME/.ssh"
AUTH_KEYS="$SSH_DIR/authorized_keys"
PUBKEY_FILE="$(dirname "$0")/mac_pubkey.txt"
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
[ "$(id -u)" -eq 0 ] || die "запустите с sudo"
id "$USER_NAME" >/dev/null 2>&1 || die "пользователь не найден: $USER_NAME"
printf '=== SSH remote access (Fedora) ===\n\n'
# openssh-server
if ! rpm -q openssh-server >/dev/null 2>&1; then
if command -v dnf >/dev/null 2>&1; then
dnf install -y openssh-server || die "dnf install openssh-server failed"
else
die "установите openssh-server вручную"
fi
fi
systemctl enable --now sshd
systemctl is-active sshd >/dev/null || die "sshd не запустился"
# firewall
if systemctl is-active firewalld >/dev/null 2>&1; then
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
printf '[ok] firewalld: ssh разрешён\n'
else
printf '[info] firewalld не активен — пропуск\n'
fi
# authorized_keys
install -d -m 700 -o "$USER_NAME" -g "$USER_NAME" "$SSH_DIR"
touch "$AUTH_KEYS"
chown "$USER_NAME:$USER_NAME" "$AUTH_KEYS"
chmod 600 "$AUTH_KEYS"
if [ -s "$PUBKEY_FILE" ]; then
if ! grep -qF "$(awk '{print $1,$2}' "$PUBKEY_FILE")" "$AUTH_KEYS" 2>/dev/null; then
cat "$PUBKEY_FILE" >>"$AUTH_KEYS"
printf '[ok] добавлен ключ из mac_pubkey.txt\n'
else
printf '[ok] ключ из mac_pubkey.txt уже есть\n'
fi
else
printf '[!] mac_pubkey.txt пуст — добавьте ключ Mac вручную:\n'
printf ' echo "ssh-ed25519 AAAA... mac-fedora" >> %s\n' "$AUTH_KEYS"
fi
# hostname для mDNS
if command -v hostnamectl >/dev/null 2>&1; then
hostnamectl set-hostname fedora 2>/dev/null || true
fi
printf '\n--- Сеть ---\n'
ip -4 -o addr show scope global 2>/dev/null | awk '{print $2, $4}' || true
printf 'hostname: %s\n' "$(hostname -f 2>/dev/null || hostname)"
printf '\n--- Готово ---\n'
printf 'С Mac: ssh %s@<IP>\n' "$USER_NAME"
printf 'mDNS: ssh %s@fedora.local\n' "$USER_NAME"
printf '\nЕсли с Mac не пингуется — изоляция хотспота или используйте BT PAN (см. REMOTE_ACCESS.md).\n'