This commit is contained in:
Luk 2026-01-26 19:13:31 +08:00
parent cbe9d7ef85
commit 002a4ccf5b

View File

@ -74,23 +74,22 @@ if [ -d "$HomePath" ]; then
read -p "***:: " AuthorizedKeys read -p "***:: " AuthorizedKeys
if [ "$AuthorizedKeys" = 'l' ]; then if [ "$AuthorizedKeys" = 'l' ]; then
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 "--- Linking [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..." echo "--- Linking [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..."
ln -s "$NIXHOME/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys" ln -s "$NIXHOME/.ssh/authorized_keys" "$HomePath/.ssh/authorized_keys"
sudo chmod 644 "$HomePath/.ssh/authorized_keys" # 确保其他用户能读取 nixhome/.ssh/authorized_keys sudo chmod 644 "$HomePath/.ssh/authorized_keys" # 确保其他用户能读取 nixhome/.ssh/authorized_keys
elif [ "$AuthorizedKeys" = 'a' ]; then elif [ "$AuthorizedKeys" = 'a' ]; then
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 "--- Copying [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..." echo "--- Copying [[$NIXHOME/authorized_keys]] to [[$HomePath/.ssh/authorized_keys]] ..."
cat "$NIXHOME/.ssh/authorized_keys" >> "$HomePath/.ssh/authorized_keys" cat "$NIXHOME/.ssh/authorized_keys" >> "$HomePath/.ssh/authorized_keys"
chmod 600 "$HomePath/.ssh/authorized_keys" chmod 600 "$HomePath/.ssh/authorized_keys"
else
exit 0
fi fi
echo 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 fi
popd popd