Previous class
Apache Configuration

Set Up Git Repo

Using SSH keys for authentication is a secure and convenient method of connecting to GitHub without needing to enter your credentials each time. Here's a step-by-step guide on how to set this up:

  1. Check for existing SSH keys: First, you should check whether you already have any SSH keys on your server. You can do this by running:
  2. bashCopy codels -al ~/.ssh
  3. If you see files named id_rsa.pub or id_dsa.pub you already have an SSH key.
  4. Generate a new SSH key: If you don't have an SSH key or want to create a new one, you can do so with the following command:
  5. mathematicaCopy codessh-keygen -t ed25519 -C "your_email@example.com"
  6. When prompted, press Enter to accept the default file location and name. You'll then be prompted to enter an optional passphrase for additional security.
  7. Add your SSH key to the ssh-agent: Start the ssh-agent in the background and add your SSH private key to the ssh-agent:
  8. bashCopy codeeval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
  9. Add your SSH key to your GitHub account: You need to give GitHub your public key. Display the contents of your public key with:
  10. bashCopy codecat ~/.ssh/id_ed25519.pub
  11. This will display a long string starting with ssh-ed25519. Copy this entire string to your clipboard.
  12. Then, on GitHub, go to Settings -> SSH and GPG keys -> New SSH key. Paste your copied public key into the "Key" field and give it a descriptive title. Finally, click "Add SSH key".
  13. Test your SSH connection: You can verify that your SSH connection to GitHub is working by running:
  14. cssCopy codessh -T git@github.com
  15. You should see a message like "Hi username! You've successfully authenticated, but GitHub does not provide shell access."

Now you can use Git commands with GitHub via SSH. When you clone a repository, be sure to use the SSH URL, which starts with git@github.com:


If user is data-www 


The issue here is that the www-data user does not have the correct permissions to write to the /var/www/.ssh directory, which is necessary for SSH to function properly.

One possible solution is to copy the SSH keys to the www-data user's home directory and then use those keys for the SSH connection.

Here's how you can do it:

  1. Create the .ssh directory in the home directory of www-data, which is usually /var/www:

bashCopy codesudo mkdir /var/www/.ssh

  1. Copy the SSH keys to the new .ssh directory:

bashCopy codesudo cp /root/.ssh/id_ed25519 /var/www/.ssh/ sudo cp /root/.ssh/id_ed25519.pub /var/www/.ssh/

  1. Change the ownership of the .ssh directory and its contents to www-data:

bashCopy codesudo chown -R www-data:www-data /var/www/.ssh

  1. Finally, when using sudo -u www-data, add -i to ensure the environment variables are set correctly:

bashCopy codesudo -u www-data -i git push -u origin master

This -i flag tells sudo to simulate an initial login, which means it will set environment variables like HOME to those of the target user (www-data in this case). This is necessary for SSH to find the correct .ssh directory.

If you ger this error message "This account is currently not available" is likely because the www-data user does not have a valid shell associated with it.

To work around this issue, we can set the HOME environment variable manually for the www-data user when running git push:

bashCopy codesudo -u www-data HOME=/var/www git push -u origin master

This command sets the HOME environment variable to /var/www just for this command, which should allow SSH to find the correct .ssh directory.

Now you should be able to push to GitHub with the new SSH key pair. Remember to use the new private key when pushing:

bash

Copy code

sudo -u www-data HOME=/var/www git push -u origin master

Steps to Pull Updates

  1. Fetch the latest changes (optional but recommended to preview without merging):
  2. git fetch origin
    
    1. This downloads updates from the remote without altering your local files.
    2. Pull the changes:
    • For the default branch (usually main or master—check with git branch):
    • git pull origin main
      
      • Replace main with your branch name if different (e.g., git pull origin develop).
      • If you're already on the branch you want to update, you can simplify to:
      • git pull
        
        • This pulls from the tracked remote/branch.


  • Mark as Completed
  • More
Next class
Set Up Postfix Mail Relay
Comments (0)
Login or Join to comment.

IMREAL.LIFE

Close