This commit is contained in:
Luk
2026-01-26 19:03:26 +08:00
parent 25632ab024
commit cbe9d7ef85
5 changed files with 50 additions and 12 deletions

View File

@@ -69,9 +69,6 @@ if [ -d "$HomePath" ]; then
# 由 root 指定新用户而创建的配置文件的 owner 是 root而不是新用户导致新用户无法读取该文件而密钥登录失败因此要重设 owner。
chown "$TheUser:$TheUser" "$HomePath/.ssh"
fi
if [ -f "$HomePath/.ssh/authorized_keys" ] || [ -L "$HomePath/.ssh/authorized_keys" ]; then
mv "$HomePath/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys.backup-$(date -u +%Y%m%dT%H%M%Sutc)"
fi
echo "::*** Append or link or omit [[$HomePath/.ssh/authorized_keys]] to config ssh server? [a] for append, [l] for link, [anything else] for omit:"
read -p "***:: " AuthorizedKeys
@@ -84,9 +81,16 @@ if [ -d "$HomePath" ]; then
echo "--- Copying [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..."
cat "$NIXHOME/.ssh/authorized_keys" >> "$HomePath/.ssh/authorized_keys"
chmod 600 "$HomePath/.ssh/authorized_keys"
else
exit 0
fi
echo
if [ -f "$HomePath/.ssh/authorized_keys" ] || [ -L "$HomePath/.ssh/authorized_keys" ]; then
mv "$HomePath/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys.backup-$(date -u +%Y%m%dT%H%M%Sutc)"
fi
fi
popd