After you have enabled 2FA for your GitHub account you must use either a personal access token or an SSH key instead of your password when accessing GitHub on the SCC command line.
- Determine URL Type
- Change URL Type
- Setting Personal Access Token
- Authenticating on the command line using SSH
Determine URL Type
First, determine which type of remote URLs you use on the SCC when you access your GitHub remote repos. Go to a directory where you have a repository on the SCC and execute the following lines:
module load git
git remote -v
You should create a personal access token if you use HTTPS remote URLs and the output looks like this:
origin https://github.com/my_user_name/my_repo_name.git (fetch)
origin https://github.com/my_user_name/my_repo_name.git (push)
You should create SSH keys if you use SSH remote URLs and the output looks like this:
origin git@github.com:my_user_name/my_repo_name.git (fetch)
origin git@github.com:my_user_name/my_repo_name.git (push)
Change URL Type
You can change which type of URLs you use with the following command (you need to execute this command for each repository you want to modify the URL):
From ssh to https:
git remote set-url origin https://github.com/my_user_name/my_repo_name.git
From https to ssh:
git remote set-url origin git@github.com:my_user_name/my_repo_name.git
Setting Personal Access Token
- Login to GitHub. In the right upper corner click the arrow next to your avatar and select “Settings”:
- On the left sidebar select “Developer settings“. Select “Personal access tokens” and “Tokens (Classic)“on the left.
- Click the “Generate new token” button (GitHub might require you to enter your GitHub password):
- In the “Note” field give the token a description, i.e “SCC Access Token”
- Select permissions for this token. The description of each permission can be found on GitHub Docs. For version control of your repositories it is enough to select “repo“, “admin:repo_hook“, and “delete repo“. Press the “Generate token” button on the bottom.
- Leave the page with the GitHub personal access token open.
- On any SCC node execute:
username@scc1[~]$ git config --global credential.helper store
This command will add the following line in your
~/.gitconfig
file:[credential] helper = store
- Create a commit in any of your current SCC repositories and then push this commit to GitHub. You will be asked to enter your username and then your password. For the password copy your “personal access token” from the GitHub webpage. Note that you will NOT see any text you paste in the SCC command window. Once you have authenticated once, you will not be prompted to enter your credentials for this or any other repository on the SCC.Alternatively, you can manually generate a
~/.git-credentials
file and store your personal access token there. This file should contain a single line:username@scc1[~]$ cat ~/.git-credentials https://your_github_user_name:your_personal_access_token@github.com
Finally, ensure that this file is only accessible by you by setting the permissions accordingly:
username@scc1[~]$ chmod 600 ~/.git-credentials
Authenticating on the command line using SSH
- First check if you already have existing SSH keys (execute on any SCC node):
username@scc1[~]$ ls -al ~/.ssh
If you see one of the following files, you already have an ssh key:
id_rsa.pub id_ecdsa.pub id_ed25519.pub
- If you do not have ssh keys, you can use
ssh-keygen
to create one. The following command can be run from anywhere on the SCC.username@scc1[~]$ ssh-keygen -t ed25519 -C "username@bu.edu"
When prompted to “Enter a file in which to save the key“, press Enter to accept the default location of the file. Next, when prompted to enter a passphrase, create a passphrase (if you do not want to enter any passphrase, just click Enter.)
- Now you should have a
~/.ssh/id_ed25519.pub
file. You can check using the following command:username@scc1[~]$ ls -al ~/.ssh
- Login to GitHub. In the right upper corner click the arrow next to your avatar and select “Settings“:
- On the left sidebar select “SSH and GPG keys“
- Click the “New SSH key” button
- In the title enter “SCC ssh key” (or any other descriptive title)
- Display the public ssh key you generated on the SCC (execute on the SCC):
cat ~/.ssh/id_ed25519.pub
- Copy the content of the above file into the “Key” field of the GitHub webpage and then click “Add ssh key“.You should now be able to push and fetch your commits between the SCC and GitHub.