How to Deploy from GitLab to an SFTP Server Automatically

Devops & Infrastructure, Git, and Tutorials

If you're updating your website by manually uploading files over SFTP or SSH-ing into your server to run git pull, there's a better way. Both methods work, but they're manual — you have to remember to do it after every change, and it's easy to miss files or deploy the wrong version.

With DeployHQ, you can connect your GitLab repository to your SSH/SFTP server and have changes deployed automatically every time you push. Only changed files are uploaded — no full re-uploads, no forgotten files, no logging into servers.

This guide covers the full setup: connecting GitLab, configuring your SFTP server, running your first deployment, and enabling automatic deployments on push.

What you'll need

  • A GitLab repository with your project code
  • An SSH/SFTP server (a VPS, dedicated server, or shared hosting with SSH access)
  • A DeployHQ account (free plan: 1 project, up to 10 deploys/day)

If you're using GitHub or Bitbucket instead, DeployHQ supports those too — see our guides for GitHub to SFTP and Bitbucket to SFTP.

Step 1: Create a new project in DeployHQ

Click the New Project button at the top of the screen.

New project

Enter a name for your project and choose GitLab. DeployHQ also supports GitHub, Bitbucket, Codebase, and manual repository configuration.

Step 2: Connect your GitLab repository

Click Create Project and you'll be prompted to log in to GitLab and authorize DeployHQ. After that, you'll see a list of your repositories.

Repository list

Select the repository you want to deploy. DeployHQ will automatically add an SSH key for access. Keep the add a webhook option checked — this enables automatic deployments later.

Step 3: Configure your SSH/SFTP server

After connecting your repository, you'll be taken to the New Server screen. Enter a name for your server, then choose SSH/SFTP as the protocol.

Enter your server details:

  • Hostname: Your server's IP address or domain name
  • Username: The SSH user (e.g., deployhq, www-data, or your hosting username)
  • Authentication: Choose SSH key (recommended) or password

SSH/SFTP details

If you choose SSH key authentication, DeployHQ generates a unique public key for your project. Copy it and add it to ~/.ssh/authorized_keys on your server. Make sure the permissions are correct:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Tip: If you run into authentication issues, see our guide to debugging SSH connections or the server troubleshooting guide.

Set the deployment path to the directory where your files should go (e.g., /var/www/html or public_html). If you leave it blank, files will be deployed to the user's home directory.

Click Create Server to finish.

Step 4: Run your first deployment

Click Deploy for the first time in the top right of your project.

First deployment

Review the details — the server and branch are selected automatically. The start revision shows The very first commit since nothing has been deployed yet. Click Deploy to transfer all files to your server.

First deployment complete

Once complete, review the deployment log to see which files were transferred.

Step 5: Enable automatic deployments

Go to the Automatic Deployments page in the left sidebar and enable it for your server:

Auto deployment

Now every push to GitLab triggers a deployment automatically. Only changed files are uploaded — DeployHQ compares commits and pushes just the diff.

New deployment

After checking your server, you can see the new files deployed:

-rw-rw-r-- 1 deployhq deployhq    0 Mar 21 15:56 testfile
-rw-rw-r-- 1 deployhq deployhq    0 Mar 21 15:56 testfile2

That's it — manual SFTP uploads replaced with automatic, git-triggered deployments.

What else can DeployHQ do?

Once basic deployments are working, there are several features that can streamline your workflow:

  • Build pipelines: Compile Sass, TypeScript, or run npm build before deploying — no need to commit compiled assets to Git
  • SSH commands: Run commands on your server after deployment (restart services, clear caches, run migrations)
  • Excluded files: Prevent specific files from being uploaded (e.g., .env, node_modules)
  • Config files: Manage server-specific configuration files outside your repository
  • Deploy to multiple servers: Push to staging and production from different branches

If you have any questions, drop us an email at support@deployhq.com or find us on Twitter/X.