Using GitHub for Student Projects on a Remote Ubuntu Server

This tutorial guides students through setting up a remote Ubuntu server for their GitHub projects. Students will connect from their Windows or Mac computers via SSH, configure Git and GitHub, and work entirely on the remote server. The professor will have access to monitor and review progress through GitHub.


1. Set Up SSH Access to the Remote Server

1.1. Generate an SSH Key on Your Local Machine

  1. Open a Terminal:
    • On Windows: Open Git Bash.
    • On Mac: Open the Terminal.
  2. Generate an SSH Key:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • Press Enter to save the key in the default location (~/.ssh/id_rsa).
    • Press Enter again for no passphrase (or set one if desired).
  3. Copy the Public Key:
    cat ~/.ssh/id_rsa.pub Copy the output of this command.

1.2. Add the SSH Key to the Remote Server

  1. Log in to the Remote Server:
    ssh username@server_ip
  2. Add the SSH Key: On the remote server:
    mkdir -p ~/.ssh echo "paste_your_copied_key_here" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
  3. Test the Connection: From your local machine:
    ssh username@server_ip If successful, you won’t be prompted for a password.

1.3. Configure the Remote Server for GitHub

  1. Generate an SSH Key on the Remote Server: On the remote server:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com" Press Enter to save the key in the default location (~/.ssh/id_rsa).
  2. Copy the SSH Key to GitHub:
    • Display the key:
      cat ~/.ssh/id_rsa.pub
    • Copy the output.
    • Log in to GitHub and go to Settings > SSH and GPG keys > New SSH Key.
    • Paste the key and save it.
  3. Test the SSH Connection:
    ssh -T git@github.com You should see:vbnetCopy codeHi <username>! You've successfully authenticated, but GitHub does not provide shell access.

2. Create a GitHub Repository

  1. Log in to GitHub: Go to https://github.com/ and log in.
  2. Create a New Repository:
    • Click New or go to https://github.com/new.
    • Name the repository (e.g., student-project).
    • Add a description and select Private.
    • Do not initialize with a README or .gitignore.
  3. Share the Repository with Your Professor:
    • Go to Settings > Collaborators and Teams.
    • Add your professor’s GitHub username jimskon as a collaborator.

3. Clone the Repository on the Remote Server

  1. Copy the Repository URL:
    • On GitHub, go to the repository and click Code > SSH.
    • Copy the SSH URL (e.g., git@github.com:username/student-project.git).
  2. Clone the Repository: On the remote server:
    git clone git@github.com:username/student-project.git cd student-project

4. Basic Git Commands

4.1. Add and Commit Changes

  1. Create or Edit Files: On the remote server, create a new file:
    echo "Initial content" > file.txt
  2. Stage Changes:
    git add .
  3. Commit Changes:
    git commit -m "Initial commit with project setup"

4.2. Push Changes to GitHub

Upload changes to the remote repository:

git push origin main

4.3. Pull Changes from GitHub

git pull origin main


5. Working with Branches

  1. Create a Branch:
    git checkout -b feature-branch
  2. Switch Between Branches:
    git checkout main
  3. Push a Branch:
    git push origin feature-branch
  4. Merge a Branch: After testing the branch, merge it into main:
    git checkout main git merge feature-branch
  5. Delete a Branch:
    git branch -d feature-branch

6. Setting Up VS Code for Remote Development

6.1. Install VS Code and Extensions

  1. Download and Install VS Code:
  2. Install the Remote-SSH Extension:
    • Open VS Code.
    • Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS).
    • Search for and install Remote – SSH.
  3. Install the GitHub Copilot Extension:
    • Search for and install GitHub Copilot.

6.2. Connect to the Remote Server

  1. Add the SSH Host in VS Code:
    • Press Ctrl+Shift+P (Cmd+Shift+P on macOS).
    • Type Remote-SSH: Add New SSH Host.
    • Enter the connection string:
      username@server_ip
    • Select the SSH configuration file location (e.g., ~/.ssh/config).
  2. Connect to the Remote Server:
    • Open the Remote Explorer in VS Code.
    • Click Connect to Host and select your server.
  3. Open the Cloned Repository:
    • Once connected, navigate to the repository directory:
      cd student-project
    • Open the directory in VS Code:
      code .

Scroll to Top