Server With Github
1. Generate an SSH Key and Add it to GitHub
If you don't have an SSH key yet, create one (make sure you're logged in as the user you're working with):
ssh-keygen -t rsa -b 4096 -C "email@example.com"
Follow the steps and leave the passphrase blank or enter it if you wish.
1.2 Copy Public Key
Copy the public SSH key to your clipboard:
cat ~/.ssh/id_rsa.pub
1.3 Add the SSH key to GitHub
- Go to: https://github.com/settings/keys
- Click New SSH key
- Paste your public key into the field
- Give it a meaningful name
- Click Add SSH key
2. Test SSH Connection to GitHub
Test if the connection is working:
ssh -T git@github.com
You will receive a message like this:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
If you receive a Permission denied
message, check if you added the correct key and try again.
3. Create the Project Directory
Create a new directory (change yourproject
to your project name):
mkdir -p /var/www/yourproject
cd /var/www/yourproject
3.2 Clone the GitHub Repository
Use SSH to clone the project (change the URL to your repository):
git clone git@github.com:USERNAME/REPOSITORY.git .
Note the period
.
at the end; this will clone the contents directly into the current directory.
4. Set Access Permissions
Ensure the correct user is the owner of the folder:
sudo chmod -R 775 /var/www/domain
sudo find /var/www/domain -type f -exec chmod 664 {} \;
sudo find /var/www/domain -type d -exec chmod 775 {} \;
sudo chmod g+s /var/www/domain
sudo chown -R xwmsdev:group /var/www/domain
sudo chmod -R g+rw /var/www/domain
sudo chmod -R g+s /var/www/domain
5. Further Use
From now on, you can simply run git pull
and git push
within /var/www/yourproject
with your user without having to enter passwords each time.
Common issues
- SSH key not recognized?
Make sure you're running
ssh-agent
and your private key is loaded. - Wrong permissions? Check the file owner and group.
- Connection refused? Make sure you have internet access and GitHub is reachable.
With these steps, your project is in /var/www
and you're ready to continue working. Success!
Server Setup
Learn how to manage and setup your linux server
Accessing Your Server Database Locally via SSH Tunnel
This guide will teach you how to access your server's database locally via an SSH tunnel. This allows you to open your database locally through a browser or client, without having to expose it publicly.