Files
fnshell/generate_ssh_key.sh
2026-01-08 15:38:01 +08:00

39 lines
963 B
Bash
Raw Permalink 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.

#!/bin/sh
set -e
# ======================================================
# OpenWrt 公钥生成脚本
# ======================================================
KEY_NAME="id_dropbear"
HIDDEN_DIR="$HOME/.ssh"
PUBLIC_DIR="$HOME/ssh_public" # 普通目录,方便用户下载
PRIV_KEY="$HIDDEN_DIR/$KEY_NAME"
PUB_KEY="$HIDDEN_DIR/$KEY_NAME.pub"
PUB_KEY_COPY="$PUBLIC_DIR/$KEY_NAME.pub"
# 创建目录
mkdir -p "$HIDDEN_DIR"
chmod 700 "$HIDDEN_DIR"
mkdir -p "$PUBLIC_DIR"
chmod 755 "$PUBLIC_DIR"
# 生成密钥
if [ ! -f "$PRIV_KEY" ]; then
echo "未发现 SSH 密钥开始生成ed25519..."
ssh-keygen -t ed25519 -f "$PRIV_KEY" -N ""
else
echo "已存在 SSH 密钥,跳过生成"
echo "✅ SSH客户端私钥位于: $PRIV_KEY"
fi
# 复制公钥到普通目录,方便用户下载
cp -f "$PUB_KEY" "$PUB_KEY_COPY"
chmod 644 "$PUB_KEY_COPY"
echo "✅ 公钥生成完成"
echo "隐藏目录: $PUB_KEY"
echo "可下载副本: $PUB_KEY_COPY"