Skip to content

Commit 7357c39

Browse files
committed
Enabled ssh login using password and added post-deploy instructions
1 parent 0a7cf03 commit 7357c39

File tree

3 files changed

+147
-2
lines changed

3 files changed

+147
-2
lines changed

.github/workflows/deploy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
- name: Create setup script with secrets
1515
run: |
1616
sed -i "s/NEW_USER=\"youruser\"/NEW_USER=\"${{ secrets.VPS_USER }}\"/" setup.sh
17+
sed -i "s/NEW_USER_PASSWORD=\"your-secure-password\"/NEW_USER_PASSWORD=\"${{ secrets.VPS_USER_PASSWORD }}\"/" setup.sh
1718
sed -i "s/SSH_PUBLIC_KEY=\"your-public-key-content\"/SSH_PUBLIC_KEY=\"${{ secrets.SSH_PUBLIC_KEY }}\"/" setup.sh
1819
1920
- name: Deploy to VPS
@@ -39,3 +40,9 @@ jobs:
3940
# Cleanup
4041
cd /
4142
rm -rf $TEMP_DIR
43+
44+
- name: Post-setup instructions
45+
run: |
46+
echo "🎉 Setup completed!"
47+
echo "⚠️ IMPORTANT: After verifying SSH key access works, disable password authentication:"
48+
echo "ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} 'sudo sed -i \"s/PasswordAuthentication yes/PasswordAuthentication no/\" /etc/ssh/sshd_config && sudo systemctl restart sshd'"

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,28 @@ First, fork this repository and make it private to safely store your configurati
3232
### 2. Configure GitHub Secrets
3333
In your forked repository, go to Settings > Secrets and variables > Actions and add the following secrets:
3434

35-
- `VPS_HOST`: Your VPS IP address
35+
- `VPS_HOST`: Your VPS IP address or hostname
3636
- `VPS_ROOT_PASSWORD`: Initial root password
3737
- `VPS_USER`: Desired username for the non-root user
38+
- `VPS_USER_PASSWORD`: Password for the new user
3839
- `SSH_PUBLIC_KEY`: Your SSH public key content (from `~/.ssh/id_rsa.pub`)
3940

41+
Example values:
42+
```bash
43+
VPS_HOST: 123.456.789.0
44+
VPS_ROOT_PASSWORD: your-initial-root-password
45+
VPS_USER: john
46+
VPS_USER_PASSWORD: your-secure-user-password
47+
SSH_PUBLIC_KEY: ssh-rsa AAAAB3NzaC1... john@localhost
48+
```
49+
50+
⚠️ Security Note:
51+
- Never commit these values directly to the repository
52+
- Always use GitHub Secrets for sensitive information
53+
- Use strong passwords for both root and user accounts
54+
- Keep your SSH private key secure
55+
56+
4057
### 3. Deploy
4158
The setup will automatically deploy when you push to the main branch, or you can manually trigger it from the Actions tab.
4259

@@ -72,7 +89,27 @@ The setup will automatically deploy when you push to the main branch, or you can
7289
### SSH Security
7390
- Key-based authentication only
7491
- Root login disabled
75-
- Password authentication disabled
92+
- Password authentication enabled. For security reasons you should disable it after successfull setup (see [Post-Setup Security Steps](#4-post-setup-security-steps) below)
93+
94+
### 4. Post-Setup Security Steps
95+
96+
After the GitHub Action completes successfully:
97+
98+
1. Test SSH key-based login:
99+
```bash
100+
ssh your-user@your-vps-host
101+
```
102+
103+
2. If SSH key access works, disable password authentication:
104+
```bash
105+
ssh your-user@your-vps-host 'sudo sed -i "s/PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config && sudo systemctl restart sshd'
106+
```
107+
108+
⚠️ Important:
109+
- Only disable password authentication after confirming SSH key access works
110+
- Keep a backup of your SSH private key
111+
- Store your VPS root password securely (in case of emergencies)
112+
- Monitor the GitHub Actions logs for the setup result
76113

77114
## 🛠️ Customization
78115

setup.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
# Variables
4+
NEW_USER="youruser"
5+
NEW_USER_PASSWORD="your-secret-password"
6+
SSH_PUBLIC_KEY="your-public-key-content"
7+
8+
# Update system
9+
apt update && apt upgrade -y
10+
11+
# Install required packages
12+
apt install -y sudo ufw fail2ban unattended-upgrades apt-listchanges
13+
14+
# Configure unattended-upgrades
15+
cat > /etc/apt/apt.conf.d/20auto-upgrades << EOF
16+
APT::Periodic::Update-Package-Lists "1";
17+
APT::Periodic::Unattended-Upgrade "1";
18+
APT::Periodic::Download-Upgradeable-Packages "1";
19+
APT::Periodic::AutocleanInterval "7";
20+
EOF
21+
22+
cat > /etc/apt/apt.conf.d/50unattended-upgrades << EOF
23+
Unattended-Upgrade::Origins-Pattern {
24+
"origin=Debian,codename=\${distro_codename},label=Debian-Security";
25+
"origin=Debian,codename=\${distro_codename}-security,label=Debian-Security";
26+
};
27+
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
28+
Unattended-Upgrade::MinimalSteps "true";
29+
Unattended-Upgrade::InstallOnShutdown "false";
30+
Unattended-Upgrade::Mail "root";
31+
Unattended-Upgrade::MailReport "on-change";
32+
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
33+
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
34+
Unattended-Upgrade::Remove-Unused-Dependencies "false";
35+
Unattended-Upgrade::Automatic-Reboot "true";
36+
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
37+
EOF
38+
39+
# Enable unattended-upgrades
40+
systemctl enable unattended-upgrades
41+
systemctl start unattended-upgrades
42+
43+
# Create new user and add to sudo group
44+
useradd -m -s /bin/bash $NEW_USER
45+
echo "$NEW_USER:$NEW_USER_PASSWORD" | chpasswd
46+
usermod -aG sudo $NEW_USER
47+
48+
# Setup SSH key for new user
49+
mkdir -p /home/$NEW_USER/.ssh
50+
echo "$SSH_PUBLIC_KEY" > /home/$NEW_USER/.ssh/authorized_keys
51+
chmod 700 /home/$NEW_USER/.ssh
52+
chmod 600 /home/$NEW_USER/.ssh/authorized_keys
53+
chown -R $NEW_USER:$NEW_USER /home/$NEW_USER/.ssh
54+
55+
# Configure SSH
56+
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
57+
sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
58+
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
59+
60+
# Configure fail2ban
61+
cat > /etc/fail2ban/jail.local << EOF
62+
[sshd]
63+
enabled = true
64+
port = ssh
65+
filter = sshd
66+
logpath = /var/log/auth.log
67+
maxretry = 3
68+
bantime = 3600
69+
findtime = 600
70+
EOF
71+
72+
# Configure firewall
73+
ufw default deny incoming
74+
ufw default allow outgoing
75+
ufw allow ssh
76+
ufw allow http
77+
ufw allow https
78+
echo "y" | ufw enable
79+
80+
# Install Docker
81+
apt install -y ca-certificates curl gnupg
82+
install -m 0755 -d /etc/apt/keyrings
83+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
84+
chmod a+r /etc/apt/keyrings/docker.gpg
85+
86+
echo \
87+
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
88+
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
89+
tee /etc/apt/sources.list.d/docker.list > /dev/null
90+
91+
apt update
92+
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
93+
94+
# Add user to docker group
95+
usermod -aG docker $NEW_USER
96+
97+
# Restart services
98+
systemctl restart sshd
99+
systemctl restart fail2ban
100+
101+
echo "Setup completed!"

0 commit comments

Comments
 (0)