This guide will walk you through the necessary steps to clone a private repo on your VPS, allowing you to access and work with your code seamlessly.
Key Takeaways
- Generating an SSH key pair on your VPS is essential for secure authentication.
- Adding the public key to your Git hosting service grants access to your private repository.
- Use the
git clone
command with the SSH URL to clone the private repository onto your VPS.
Step-by-Step Guide
1. Access your VPS through SSH
To begin, establish an SSH connection to your VPS using the provided credentials. This will give you command-line access to your server.
2. Navigate to the desired directory
Once connected to your VPS, navigate to the directory where you want to clone the private repository. Use the cd
command to change directories.
cd /path/to/directory
3. Generate an SSH key pair
If you don’t already have an SSH key pair on your VPS, generate one using the ssh-keygen
command. This will create both a private and public key.
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Press Enter to accept the default file location, and optionally provide a passphrase for added security.
4. Add the public key to your Git hosting service
Copy the contents of the public key using the following command:
cat ~/.ssh/id_rsa.pub
Next, go to the website of your Git hosting service, such as GitHub, and navigate to the SSH keys section in your account settings. Add a new SSH key and paste the copied public key. Give it a meaningful title for identification, then save the new SSH key.
5. Clone the private repository
Back in your VPS terminal, use the git clone
command to clone the private repository. Replace <repository-url>
with the SSH URL of your private repository.
git clone [email protected]:username/repo.git
Enter your passphrase (if you set one) if prompted, and the private repository will be cloned onto your VPS.
Conclusion
Now you can access and work with your private code repository on your VPS without any hassle. Happy coding!