Table of Contents
- 1 Automating DirectAdmin Server Deployments from GitHub Using GitHub Actions and Password-Based SSH Authentication
- 2 Step 1: Create a GitHub Repository
- 3 Step 2: Set Up SSH Password Authentication on DirectAdmin
- 4 Step 3: Set Up the Development Environment on Your Local Machine
- 5 Step 4: Store Your SSH Password in GitHub Secrets
- 6 Step 5: Set Up GitHub Actions for Automatic Deployment
- 7 Step 6: Test the Deployment
- 8 Conclusion
Automating DirectAdmin Server Deployments from GitHub Using GitHub Actions and Password-Based SSH Authentication
Automating deployments ensures that your website or application is always up to date with minimal manual effort. By integrating GitHub with DirectAdmin and using GitHub Actions for deployment, you can push changes to GitHub from your local machine and have them automatically deployed to your DirectAdmin server.
In this guide, we’ll demonstrate how to automate DirectAdmin Server deployments from GitHub using GitHub Actions and password-based SSH authentication.
Prerequisites
- A GitHub account and repository for your website or application.
- Access to a DirectAdmin server.
- SSH password for a user account on your DirectAdmin server.
- Git installed on your local machine.
Step 1: Create a GitHub Repository
If you don’t already have a repository for your project, let’s create one on GitHub.
- Go to GitHub and log in.
- In the upper-right corner, click the + button and select New repository.
- Name your repository (e.g.,
my-website), provide a description, and set it to private (or public). - Click Create repository.
Step 2: Set Up SSH Password Authentication on DirectAdmin
Ensure your DirectAdmin server is ready for password-based SSH authentication.
- Log in to your DirectAdmin server:
ssh testuser@your-server-ip
- Verify that password-based SSH authentication is enabled. If it’s not, enable it in the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Make sure the following settings are in place:
PasswordAuthentication yes
PubkeyAuthentication yes
- Save the file and restart the SSH service:
sudo systemctl restart ssh
Step 3: Set Up the Development Environment on Your Local Machine
Now, let’s set up a local development environment where you can make changes to your website or application and push them to GitHub.
Install Git (if it’s not already installed)
On macOS or Linux, open a terminal and run:
sudo apt install git # For Linux
brew install git # For macOS (with Homebrew installed)
For Windows, you can download Git from Git’s official website.
Clone the GitHub Repository
- Open a terminal (or Git Bash on Windows).
- Clone the repository you created on GitHub:
git clone git@github.com:your_username/my-website.git
- Navigate into the repository directory:
cd my-website
Create a File and Push it to GitHub
- Create a simple HTML file in the repository folder on your local machine:
echo "<h1>Welcome to my website</h1>" > index.html
- Add the file to Git:
git add index.html
- Commit the file:
git commit -m "Add index.html"
- Push the changes to GitHub:
git push origin main
Step 4: Store Your SSH Password in GitHub Secrets
To enable GitHub Actions to authenticate with your DirectAdmin server, store your SSH password securely in GitHub Secrets.
- Go to your GitHub repository.
- Navigate to Settings > Secrets and Variables > Actions.
- Click New repository secret.
- Name the secret
SSH_PASSWORDand paste your SSH password into the value field. - Click Add secret.
Step 5: Set Up GitHub Actions for Automatic Deployment
Now that your local machine and GitHub repository are set up, you can configure GitHub Actions to automatically deploy changes to your DirectAdmin server whenever you push code to GitHub.
- In your local repository, create a new directory for your GitHub Actions workflows:
mkdir -p .github/workflows
- Inside this directory, create a workflow file called
deploy.yml:
nano .github/workflows/deploy.yml
- Add the following content to the file:
name: Deploy to DirectAdmin
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install SSH and sshpass
run: |
sudo apt-get update
sudo apt-get install -y openssh-client sshpass
- name: Deploy to DirectAdmin server using password authentication
run: |
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no testuser@your-server-ip 'cd /home/testuser/public_html && git pull origin main'
- Push the GitHub Actions workflow to GitHub:
git add .github/workflows/deploy.yml
git commit -m "Add GitHub Actions deployment workflow"
git push origin main
Step 6: Test the Deployment
Now that everything is set up, let’s test the deployment process.
- Make a change in your local machine by editing
index.html:
echo "<h1>Updated website content</h1>" > index.html
- Commit and push the changes to GitHub:
git add index.html
git commit -m "Update website content"
git push origin main
- Check GitHub Actions:
- Go to the Actions tab in your GitHub repository.
- You should see the workflow running, automatically deploying the changes to your DirectAdmin server.
- Verify the changes:
- Visit your website to confirm that the updated content has been deployed.
Conclusion
By following this guide, you have successfully set up an automated deployment process from your local development environment to a DirectAdmin server using GitHub Actions and password-based SSH authentication. Consider switching to SSH key-based authentication for enhanced security.