{"id":138130,"date":"2021-12-10T13:43:01","date_gmt":"2021-12-10T18:43:01","guid":{"rendered":"http:\/\/www.bu.edu\/tech\/?page_id=138130"},"modified":"2024-02-21T09:54:07","modified_gmt":"2024-02-21T14:54:07","slug":"using-scc-with-github-2fa","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/tech\/support\/research\/system-usage\/connect-scc\/access-and-security\/using-scc-with-github-2fa\/","title":{"rendered":"Using SCC with GitHub 2FA"},"content":{"rendered":"<p>After you have <a href=\"https:\/\/docs.github.com\/en\/authentication\/securing-your-account-with-two-factor-authentication-2fa\/configuring-two-factor-authentication\">enabled 2FA for your GitHub account<\/a> you must use either a personal access token or an SSH key instead of your password when accessing GitHub on the SCC command line.<\/p>\n<ul>\n<li><a href=\"#DET_URL_TYPE\">Determine URL Type<\/a><\/li>\n<li><a href=\"#CHANGE_URL_TYPE\">Change URL Type<\/a><\/li>\n<li><a href=\"#SET_PAT\">Setting Personal Access Token<\/a><\/li>\n<li><a href=\"#AUTH\">Authenticating on the command line using SSH<\/a><\/li>\n<\/ul>\n<h2><a name=\"DET_URL_TYPE\"><\/a>Determine URL Type<\/h2>\n<p>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:<\/p>\n<pre class=\"code-block\"><code><span class=\"command\">module load git  \r\ngit remote -v<\/span><\/code><\/pre>\n<p>You should create a <strong>personal access token<\/strong> if you use HTTPS remote URLs and the output looks like this:<\/p>\n<pre class=\"code-block\"><code>origin <strong><i>https:\/\/github.com\/<\/i><\/strong><span class=\"placeholder\">my_user_name\/my_repo_name.git<\/span> (fetch)\r\norigin <strong><i>https:\/\/github.com\/<\/i><\/strong><span class=\"placeholder\">my_user_name\/my_repo_name.git<\/span> (push)<\/code><\/pre>\n<p>You should create <strong>SSH keys<\/strong> if you use SSH remote URLs and the output looks like this:<\/p>\n<pre class=\"code-block\"><code>origin <strong><i>git@github.com<\/i><\/strong>:<span class=\"placeholder\">my_user_name\/my_repo_name.git<\/span> (fetch)\r\norigin <strong><i>git@github.com<\/i><\/strong>:<span class=\"placeholder\">my_user_name\/my_repo_name.git<\/span> (push)<\/code><\/pre>\n<h2><a name=\"CHANGE_URL_TYPE\"><\/a>Change URL Type<\/h2>\n<p>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):<\/p>\n<h4>From ssh to https:<\/h4>\n<pre class=\"code-block\"><code><span class=\"command\">git remote set-url origin<\/span> https:\/\/github.com<span class=\"placeholder\">\/my_user_name\/my_repo_name.git<\/span><\/code><\/pre>\n<h4>From https to ssh:<\/h4>\n<pre class=\"code-block\"><code><span class=\"command\">git remote set-url origin<\/span> git@github.com:<span class=\"placeholder\">my_user_name\/my_repo_name.git<\/span><\/code><\/pre>\n<h2><a name=\"SET_PAT\"><\/a>Setting Personal Access Token<\/h2>\n<p><a href=\"https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/creating-a-personal-access-token\">GitHub Directions<\/a><\/p>\n<ol>\n<li>Login to GitHub. In the right upper corner click the arrow next to your avatar and select &#8220;Settings&#8221;:<br \/>\n<img loading=\"lazy\" src=\"\/tech\/files\/2021\/04\/settings.png\" width=\"220\" height=\"512\" class=\"alignnone\" alt=\"From the GitHub interface, users click the avatar in the top right corner. Then, select Settings from the dropdown menu.\" \/><\/li>\n<li>On the left sidebar select &#8220;<i>Developer settings<\/i>&#8220;. Select &#8220;<i>Personal access tokens<\/i>&#8221; and &#8220;<i>Tokens (Classic)<\/i>&#8220;on the left.<\/li>\n<li>Click the \u201c<i>Generate new token<\/i>&#8221; button (GitHub might require you to enter your GitHub password):<br \/>\n<img loading=\"lazy\" src=\"\/tech\/files\/2021\/04\/pat.png\" width=\"512\" height=\"80\" class=\"alignnone\" alt=\"Click rectangle &quot;Generate new token&quot; button in top right of GitHub window.\" \/><\/li>\n<li>In the &#8220;<i>Note<\/i>\u201d field give the token a description, i.e \u201c<i>SCC Access Token<\/i>\u201d<\/li>\n<li>Select permissions for this token. The <a href=\"https:\/\/docs.github.com\/en\/developers\/apps\/scopes-for-oauth-apps#available-scopes\">description of each permission can be found on GitHub Docs<\/a>. For version control of your repositories it is enough to select &#8220;<i>repo<\/i>&#8220;, &#8220;<i>admin:repo_hook<\/i>&#8220;, and &#8220;<i>delete repo<\/i>&#8220;. Press the \u201c<i>Generate token<\/i>&#8221; button on the bottom.<\/li>\n<li>Leave the page with the GitHub <i>personal access token<\/i> open.<\/li>\n<li>On any SCC node execute:\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">git config --global credential.helper store<\/span><\/code><\/pre>\n<p>This command will add the following line in your <code>~\/.gitconfig<\/code> file:<\/p>\n<pre class=\"code-block\"><code><span class=\"command\"><span class=\"output\">[credential]\r\n        helper = store<\/span><\/span><\/code><\/pre>\n<\/li>\n<li>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 &#8220;<i>personal access token<\/i>&#8221; 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 <code>~\/.git-credentials<\/code> file and store your <i>personal access token<\/i> there. This file should contain a single line:\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">cat<\/span> ~\/.git-credentials\r\nhttps:\/\/<span class=\"placeholder\">your_github_user_name<\/span>:<span class=\"placeholder\">your_personal_access_token<\/span>@github.com<\/code><\/pre>\n<p>Finally, ensure that this file is only accessible by you by setting the permissions accordingly:<\/p>\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">chmod<\/span> 600 ~\/.git-credentials<\/code><\/pre>\n<\/li>\n<\/ol>\n<h2><a name=\"AUTH\"><\/a>Authenticating on the command line using SSH<\/h2>\n<p><a href=\"https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/connecting-to-github-with-ssh\">GitHub Directions<\/a><\/p>\n<ol>\n<li>First check if you already have existing SSH keys (execute on any SCC node):\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">ls<\/span> -al ~\/.ssh<\/code><\/pre>\n<p>If you see one of the following files, you already have an ssh key:<\/p>\n<pre class=\"code-block\"><code>id_rsa.pub\r\nid_ecdsa.pub\r\nid_ed25519.pub<\/code><\/pre>\n<\/li>\n<li>If you do not have ssh keys, you can use <code><span class=\"command\">ssh-keygen<\/span><\/code> to create one. The following command can be run from anywhere on the SCC.\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">ssh-keygen -t ed25519 -C \"<span class=\"placeholder\">username@bu.edu<\/span>\"<\/span><\/code><\/pre>\n<p>When prompted to &#8220;<i>Enter a file in which to save the key<\/i>&#8220;, press <i>Enter<\/i> 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 <i>Enter<\/i>.)<\/li>\n<li>Now you should have a <code>~\/.ssh\/id_ed25519.pub<\/code> file. You can check using the following command:\n<pre class=\"code-block\"><code><span class=\"prompt\">username@scc1[~]$<\/span> <span class=\"command\">ls -al ~\/.ssh<\/span><\/code><\/pre>\n<\/li>\n<li>Login to GitHub. In the right upper corner click the arrow next to your avatar and select &#8220;<i>Settings<\/i>&#8220;:<br \/>\n<img loading=\"lazy\" src=\"\/tech\/files\/2021\/04\/settings.png\" width=\"220\" height=\"512\" class=\"alignnone\" alt=\"From the GitHub interface, users click the avatar in the top right corner. Then, select Settings from the dropdown menu.\" \/><\/li>\n<li>On the left sidebar select &#8220;<i>SSH and GPG keys<\/i>&#8220;<\/li>\n<li>Click the \u201c<i>New SSH key<\/i>&#8221; button<\/li>\n<li>In the title enter &#8220;<i>SCC ssh key<\/i>&#8221; (or any other descriptive title)<\/li>\n<li>Display the public ssh key you generated on the SCC (execute on the SCC):\n<pre class=\"code-block\"><code><span class=\"command\">cat<\/span> ~\/.ssh\/id_ed25519.pub<\/code><\/pre>\n<\/li>\n<li>Copy the content of the above file into the &#8220;<i>Key<\/i>&#8221; field of the GitHub webpage and then click &#8220;<i>Add ssh key<\/i>&#8220;.You should now be able to push and fetch your commits between the SCC and GitHub.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1692,"featured_media":0,"parent":137913,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/138130"}],"collection":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/users\/1692"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/comments?post=138130"}],"version-history":[{"count":8,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/138130\/revisions"}],"predecessor-version":[{"id":150538,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/138130\/revisions\/150538"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/137913"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/media?parent=138130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}