Related
See also my post on setting up Python on Windows as well as R.

Arch Linux

Install ksshaskpass and create a symlink to enable VS Code to recognise it:

sudo pacman -Syu openssh kwalletmanager kwallet-pam ksshaskpass git-lfs
sudo ln /usr/bin/ksshaskpass /usr/lib/ssh/ssh-askpass

Configure Git global user settings:

git config --global user.name "Your Name"
git config --global user.email "email@example.com"

Check for existing SSH keys:

ls -al ~/.ssh

If no keys exist, generate a new key using ED25519 (recommended over RSA):

ssh-keygen -t ed25519 -C "<comment>"

Start the SSH agent as follows (also add these to ~/.bashrc or equivalent):

eval $(ssh-agent)
ssh-add

Copy the SSH public key to your clipboard (saved at ~/.ssh/id_ed25519.pub) and add to GitHub/GitLab. The key can be used for authentication, signing, or both.

Configure SSH key for signing commits:

git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub

In VS Code / VSCodium, enable commit signing in the settings:

"git.enableCommitSigning": true

Windows

Update the PowerShell execution policy:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

Windows Subsystem for Linux (WSL) - Ubuntu

In PowerShell, install Visual Studio Code and WSL (Ubuntu):

winget install vscode
wsl --install

Install the WSL and Remote - SSH VS Code extensions locally in Windows.

Set up SSH (for authentication and signing) and Git using the WSL Bash shell (this is identical to setting up SSH on Ubuntu):

sudo apt install ssh-askpass keychain git-lfs
ssh-keygen -t ed25519 -C "<comment>"
eval "$(ssh-agent -s)"
eval `keychain --eval`
ssh-add
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub

Add the following to WSL’s ~/.bashrc:

eval "$(ssh-agent -s)"
eval `keychain --eval`
ssh-add

Copy the SSH public key to your clipboard (saved at ~/.ssh/id_ed25519.pub) and add to GitHub and/or GitLab through their settings. The key can be used for authentication, signing, or both.

Install packages such as Miniconda using the WSL Bash shell (use the Unix shell script to install).

Clone Git repositories using the WSL Bash shell using SSH.

Launch VS Code using the WSL Bash shell by navigating to the Git repository directory and running code ..

Install local VS Code extensions in WSL.

Windows without WSL

In PowerShell:

winget install vscode
winget install git.git
winget install github.githubdesktop
winget install github.cli
winget install github.gitlfs
git config --global user.name "Your Name"
git config --global user.email "email@example.com"

Authenticate GitHub Desktop and GitHub CLI using your GitHub account.

Note
That’s all you need to do to get GitHub working over HTTPS on Windows. The following points are for setting up SSH for committing and signing, which is optional.

To also sign commits using an SSH key, do the following:

  • Create a new SSH key pair with ssh-keygen -t ed25519 -C "<comment>" in Git Bash (alternatively, copy the key pair created in WSL into ~/.ssh):

    ssh-keygen -t ed25519 -C "<comment>"
    
  • Then, in Git Bash:

    eval $(ssh-agent)
    ssh-add
    git config --global commit.gpgsign true
    git config --global gpg.format ssh
    git config --global user.signingkey ~/.ssh/id_ed25519.pub
    
  • Add the following to ~/.bashrc:

    eval $(ssh-agent)
    ssh-add
    
  • Copy the SSH public key to your clipboard (saved at ~/.ssh/id_ed25519.pub) and add to GitHub/GitLab. The key can be used for authentication, signing, or both.

  • Note: this may not work, so try OpenSSH for Windows instead of the SSH that comes with Git.

  • Set OpenSSH to run automatically. Go to Task Manager > Services > Open Services, find OpenSSH Authentication Agent > Properties > Startup Type > Automatic.

  • Configure Git to use OpenSSH (in Git Bash):

    git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
    eval $(ssh-agent)
    ssh-add
    
  • To revert to the SSH agent supplied by Git for Windows (in Git Bash):

    git config --global core.sshCommand "C:/Program Files/Git/usr/bin/ssh.exe"
    eval $(ssh-agent)
    ssh-add
    

Testing if SSH works

Use the following commands to test whether SSH has been configured properly for GitLab, GitHub, and GitHub Gist:

ssh -T git@gitlab.com  # GitLab
ssh -T git@github.com  # GitHub

Info
If connection to these hosts are being tested for the first time, a warning might appear stating that the authenticity of the host can’t be established and if you want to continue connecting. If the fingerprint matches that of GitLab or GitHub, type “yes” and continue.

You should get the following outputs if it’s working:

Welcome to GitLab, @username!

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

If you don’t get the above, then there may be issues with the connection. To troubleshoot, use the following command to run SSH in verbose mode:

ssh -Tvvv git@gitlab.com  # GitLab
ssh -Tvvv git@github.com  # GitHub

Enabling SSH via HTTPS might resolve this problem.

First, test if SSH is working over the HTTPS port (443); you should get the same outputs as above:

ssh -T -p 443 git@altssh.gitlab.com  # GitLab
ssh -T -p 443 git@ssh.github.com  # GitHub

If it works, create a file called ~/.ssh/config and add the following configurations:

Host gitlab.com
  Hostname altssh.gitlab.com
  User git
  Port 443
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519

Host github.com
  Hostname ssh.github.com
  User git
  Port 443
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ed25519

Test again to see if everything is working:

ssh -T git@gitlab.com  # GitLab
ssh -T git@github.com  # GitHub

Updating remote URLs for SSH

If the local repository was cloned using HTTPS and you’re using SSH, the remote URL must be updated to use SSH. To check the existing remote:

git remote -v

To change the remote URL to SSH:

git remote set-url origin git@gitlab.com:USERNAME/REPOSITORY.git  # GitLab
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git  # GitHub

Leave a comment

Your email address will not be published. Required fields are marked *.

Loading...