SSH, Git and Github

Basic commands HPC Launch https://hds-sandbox.github. io/HPC-lab/

Alba Refoyo
Jennifer Bartell

2025-04-15

Generate SSH Key Pair

Navigate to the location where all SSH keys are stored to generate a new one (skip these first two commands if you haven’t used SSH keys before).

Mac/Linux
cd ~/.ssh 

Windows
cd C:\Users\<YourUsername>\.ssh

We will specify the type of key to create with the option -t (default) and use a filename that describes what the key is for (e.g. id_UCloud), and don’t enter a passphrase:

ssh-keygen -t ed25519 
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/gsd818/.ssh/id_ed25519): id_UCloud
Your identification has been saved in id_UCloud
Your public key has been saved in id_UCloud.pub
...

Windows users (skip otherwise)

On Powershell
# By default the ssh-agent service is disabled. Configure it to start automatically.
# Make sure you're running as an Administrator.
Get-Service ssh-agent | Set-Service -StartupType Automatic

# Start the service
Start-Service ssh-agent

# This should return a status of Running
Get-Service ssh-agent

On WSL
eval `ssh-agent -s`

On MombaXterm, follow the instructions here.

Once, we have generated your SSH keys, add the key to your system:

## Now load your key files into ssh-agent
ssh-add id_UCloud

Do you get a message similar to this?

entity added: id_UCloud (gsd818@SUN1029429)

Then, copy the public key, either using cat to print the content of the file or as follows:

cat id_UCloud.pub | pbcopy 

You can now paste the public SSH key on UCloud. You’ll need to enable SSH access when you submit a job so you can SSH in.

Submit a new job on UCloud and configure SSH access

Once the job starts, the SSH command appears in the progress view and can be run locally from your terminal

Connecting GitHub with UCloud

Create a new GitHub account if you don’t have one yet. Then, go to repositories and create a new one (e.g. SandboxIntro). Alternatively, you can also fork one of our repositories or if you already have one feel free to use that instead.

Now, we need to create a token classic (for general use). Go to your profile and on the right-side menu select:

Settings > Developer settings (at the bottom) > Personal access tokens > Tokens (classic) > Generate new token (classic).

  • Note: git commit UCloud
  • Select scope: ✅ repo (top option)
  • Do not set a expiration date

Please, remember to save the generated token somewhere locally and safe. You won’t be able to see/copy it again.

Use the token as your password when performing Git operations like push or commit from the HPC.

Then, we will generate SSH key on UCloud following these steps

  1. Submit a new job using the Terminal app and mount your personal drive
  2. Change directory to your personal drive (e.g. cd /work/myNameXXX/)
  3. Create a new folder named ssh, where you will store your new SSH keys
  4. Generate a new key (no need for paraphrase) and save it as e.g. id_repo1
ssh-keygen -t ed25519
  1. Copy the public key (e.g. id_repo1.pub)
  2. Add the key to the repository you have created or forked from us on GitHub: YOUR-REPO > Settings > Deploy keys > Add deploy key. The new deploy key can be named as e.g. UCloud-repo1

Finally, to streamline pushing changes…

  1. Modify/Create the initialization bash script to include this code
setup.sh
eval `ssh-agent -s`
ssh-add /work/ssh/id_repo1
git config --global user.name "add here your name"
git config --global user.email "add here your email"
bash -i 

You can now git commit and push using the token as password to save all changes to your repository. Let’s give it a try!

Submit a new job on UCloud. Do not forget to mount your personal drive and use the initialization bash script you just created. Once, the job is running, change directory to your personal drive, and clone your repository.

Example repo
git clone <https://github.
com/hds-sandbox/cookiecutter-template>

Now, modify or create a new file in your repository. This is a test to understand how to push changes to GitHub.

git add . 
git commit -m "added new file"
git push 

You will be asked to enter your GitHub username and the password. When you work from HPCs, you need to enter the token as your password.

Go to GitHub and check if those changes are now visible.