Created
March 22, 2024 09:30
-
-
Save xausky/4d3fe754652cac174a4b945f7ab0af7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 创建用户xausky,如果用户已存在,则不创建 | |
if ! id "xausky" &>/dev/null; then | |
useradd -m xausky | |
echo "User xausky created." | |
else | |
echo "User xausky already exists." | |
fi | |
# 配置sudo免密码 | |
echo "xausky ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/xausky | |
# 为用户xausky创建.ssh目录和authorized_keys文件,并设置合适的权限 | |
su - xausky -c "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys" | |
su - xausky -c "chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" | |
# 从GitHub获取xausky的SSH公钥并添加到authorized_keys | |
su - xausky -c "curl https://github.com/xausky.keys >> ~/.ssh/authorized_keys" | |
echo "Setup complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment