Use Git over SSH on Bluehost

This document explains how to use Git over SSH on Bluehost. Using SSH provides a secure way to push and pull code from your Bluehost server. This setup requires configuring SSH keys for authentication.

Get 60% OFF on Bluehost Hosting →

Generate an SSH Key Pair

Open your terminal on your local machine.

Run the command: ssh-keygen -t rsa -b 4096 -C "your_email@example.com" (replace with your email).

When prompted, choose a file location to save the key pair (or press Enter for the default).

You can optionally set a passphrase for added security.

Add the Public Key to Bluehost

Log in to your Bluehost cPanel.

Navigate to Security → SSH Access.

Click 'Manage SSH Keys'.

You may need to enable SSH Access first.

Click 'Import Key'.

Paste the contents of your public key file (usually id_rsa.pub) into the 'Public Key' field.

Give the key a name in the 'Key Name' field.

Click 'Import'.

Configure Git

Test your SSH connection by running: ssh yourusername@yourdomain.com (replace with your Bluehost username and domain).

If prompted, type 'yes' to add the host to your known_hosts file.

Configure your Git remote URL to use SSH: git remote set-url origin ssh://yourusername@yourdomain.com/~/path/to/your/repository.git (replace values appropriately).

Verify the Setup

Try cloning your repository from Bluehost to your local machine using: git clone ssh://yourusername@yourdomain.com/~/path/to/your/repository.git.

Make a small change to a file in your local repository.

Commit the change and push it to Bluehost: git push origin main.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

ssh yourusername@yourdomain.com

git remote set-url origin ssh://yourusername@yourdomain.com/~/path/to/your/repository.git

Examples

  • Public Key File Path: /home/yourusername/.ssh/id_rsa.pub
  • Git Remote URL: ssh://myuser@example.com/~/public_html/myproject.git
  • cPanel Path: Security → SSH Access → Manage SSH Keys → Import Key
  • Test command: ssh myuser@example.com

Tips

  • Always keep your private key secure.
  • Use a strong passphrase for your SSH key.
  • Regularly review your authorized SSH keys in cPanel.
  • Disable password authentication for SSH after setting up key-based authentication for better security.

Get Started With Bluehost — Launch Your Site in Minutes →

FAQ

Q: How do I find my Bluehost username?

A: Your Bluehost username is usually the same as the account username shown in your cPanel.

Q: What if I get a 'Permission denied (publickey)' error?

A: This means your public key was not correctly added to Bluehost. Double-check that you copied the entire key and that the permissions are correct.

Q: Where should I store my Git repository on Bluehost?

A: A common location is within your home directory (e.g., /home/yourusername/myrepository.git). You can also place it in the public_html directory if you intend to serve the files via a web server.

This document is for informational purposes only. It is not official and is not affiliated with or endorsed by Bluehost. Information provided here may be outdated and should not be considered professional advice. This document may contain affiliate links.