#!/bin/bash
# 修复 authorized_keys - 确保每个公钥都是单独一行

SERVER_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCm/leXfpZ1Ycm7uL3sXYU1Hp5TO42EqUnD5H7SwveTIusF14e5oZf5P72fttGLIxQMFgGdXzu4+coWPmpGsUHjqm4g0FbeL+mjM+0cnqeggoueoFm3dk9y+9jaogjuR2VY9oqbdOvD+L0IfvS+t6WJrYif1MdXOYnH5MfNYtrLb/MWCDiTT4w/Cw0QKSSB3S3+nvYqxD1Ep+wdLrd+SfgiMi2qU/bO7ccEgXwjqiI/4LDHh2r5oajkvdRSuQ75PLSRdFfR+aq/NcV/NJE3YOcb8wVhvVjZZSXQyy8PlqLn6N58qckharwAj6vRxC9CbWB+XDrLOMWOtdq7T7iBPJmy1wVDDyva9wEnKiprdXf+2F/Q57SJjcbPTCt6TqXggQ0hVf7tOK6Wefk5dwPW0P3mdzPTp91s9iU96kM+9VSY0dhKEnim+6IncxEK+hnbAbGOX66MuRmK9u7dYlsjhFq345rNXmkXIIY3VU2GuCBLB4bk88pNubrd8y9S03JbZIU= root@vps21249823.hosteons.com"
MAC_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDuLPlB6X9JC2uP9urgA94wCr7VBPKAX+4j9hR5wc5U5rPDxhKWbFBzRiFU/cssCZlcZbuoWPjrxwtTKR6Tq1++ugHffa2poulXCoufaN5s9kN6US8DNe/q7dulAomwd0pjSDTjhQR4OQG847PqfXz/quU96RfpOrn1WqSRTrzPnVZ885ApNUB7SHd74jrYslwoDRsJu+mS6jjI7NHdNUKTAUBsZWWPmjNO4X1+vEwwK6dZg9i1Z+sz5kLxZ0w+fI1hO6rtR5MPZh8G9JRWiVw3HN0vQtf3zxYtDnzPxELfiE10cctDaDqwMKZ6K73WNlkmoNuM7we7eRlarPGWmGu9 houzi@MichaeldeMBP.lan"

AUTH_KEYS="/c/Users/houzi/.ssh/authorized_keys"

echo "=== 修复 authorized_keys 文件 ==="
echo ""

# 完全重写文件，每个公钥一行
cat > "$AUTH_KEYS" << 'EOF'
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCm/leXfpZ1Ycm7uL3sXYU1Hp5TO42EqUnD5H7SwveTIusF14e5oZf5P72fttGLIxQMFgGdXzu4+coWPmpGsUHjqm4g0FbeL+mjM+0cnqeggoueoFm3dk9y+9jaogjuR2VY9oqbdOvD+L0IfvS+t6WJrYif1MdXOYnH5MfNYtrLb/MWCDiTT4w/Cw0QKSSB3S3+nvYqxD1Ep+wdLrd+SfgiMi2qU/bO7ccEgXwjqiI/4LDHh2r5oajkvdRSuQ75PLSRdFfR+aq/NcV/NJE3YOcb8wVhvVjZZSXQyy8PlqLn6N58qckharwAj6vRxC9CbWB+XDrLOMWOtdq7T7iBPJmy1wVDDyva9wEnKiprdXf+2F/Q57SJjcbPTCt6TqXggQ0hVf7tOK6Wefk5dwPW0P3mdzPTp91s9iU96kM+9VSY0dhKEnim+6IncxEK+hnbAbGOX66MuRmK9u7dYlsjhFq345rNXmkXIIY3VU2GuCBLB4bk88pNubrd8y9S03JbZIU= root@vps21249823.hosteons.com
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDuLPlB6X9JC2uP9urgA94wCr7VBPKAX+4j9hR5wc5U5rPDxhKWbFBzRiFU/cssCZlcZbuoWPjrxwtTKR6Tq1++ugHffa2poulXCoufaN5s9kN6US8DNe/q7dulAomwd0pjSDTjhQR4OQG847PqfXz/quU96RfpOrn1WqSRTrzPnVZ885ApNUB7SHd74jrYslwoDRsJu+mS6jjI7NHdNUKTAUBsZWWPmjNO4X1+vEwwK6dZg9i1Z+sz5kLxZ0w+fI1hO6rtR5MPZh8G9JRWiVw3HN0vQtf3zxYtDnzPxELfiE10cctDaDqwMKZ6K73WNlkmoNuM7we7eRlarPGWmGu9 houzi@MichaeldeMBP.lan
EOF

echo "✓ 已重写 authorized_keys（每个公钥一行）"
echo ""

# 设置权限
WIN_PATH="C:\\Users\\houzi\\.ssh\\authorized_keys"
icacls.exe "$WIN_PATH" //inheritance:r > /dev/null 2>&1
icacls.exe "$WIN_PATH" //grant "houzi:(F)" > /dev/null 2>&1
icacls.exe "$WIN_PATH" //grant "SYSTEM:(R)" > /dev/null 2>&1

echo "✓ 权限已设置"
echo ""

echo "=== 验证文件 ==="
echo "行数: $(wc -l < "$AUTH_KEYS")"
echo "内容:"
cat "$AUTH_KEYS"
echo ""
echo "完成！"
