...
To store your authentication credentials for git, use a hidden folder called “.ssh.” First,
check to see if the folder exists with ls –a.Code Block ls –a
If not, create it using the command
mkdir .ssh:Code Block mkdir .ssh
Confirm this works by entering ls –a to see all objects in the current directory. You should see the .ssh listed:
Code Block ls –a
Generate a new key to store in this location by typing the following command and then hitting the Enter key:
It will output the following message: “Generating public/private rsa key pair.”
It will ask you where to save the file and to enter a passphrase with the following three
prompts. Hit the Enter key each time (no need to enter anything else) to accept the
defaults.
• “Enter file in which to save the key:”
• “Enter passphrase (empty for no passphrase):”
• “Enter same passphrase again:”After the following confirmation messages, the new SSH key is now stored in the .ssh
folder.
• “Your identification has been saved in /c/Users/SDCusername/.ssh/id_rsa.”
• “Your public key has been saved in /c/Users/SDCusername/.ssh/id_rsa.pub.” The default key file name is id_rsa and is saved under the .ssh folder (e.g.,
C:/Users/[SDCusername]/.ssh/ in Windows; $HOME/.ssh/id_rsa in Linux)You now need to provide the public part of this key to GitLab by copying the “.pub” part
of the key. Here are the different options for copying the public SSH key. Option 1:
On Windows, open the id_rsa.pub file (under the C:/Users/[SDCusername]/.ssh folder) in
a text editor (Notepad) and copy the entire key by using Select All then Copy. Be careful
not to accidentally change anything!
Option 2:
Copy your public SSH key to the clipboard by using one of the commands below
depending on your Operating System: Git Bash on Windows:Code Block cat ~/.ssh/id_rsa.pub | clip
WSL/GNU/Linux (requires the xclip package):
Code Block xclip -sel clip < ~/.ssh/id_rsa.pub
If using Jupyter, use the head command. Right-click on the output and click copy:
Code Block head ~/.ssh/id_rsa.pub
8. From the GitLab home page, add your public SSH key to your GitLab account:
a. In the upper-right corner, click on your avatar image and then click Settings.
b. From the left navigation menu, click SSH Keys.
c. In the Key field, paste your public SSH key.
d. The Title field will be automatically populated with SDCusername@securedatacommons.com.
e. Click the Add key button.
...
To test whether your SSH key was added correctly, run the following command in your
terminal:Code Block ssh -T git@scm. internal.sdc.dot.gov
...
The first time you connect to GitLab via SSH, you will be asked to verify the authenticity
of the GitLab host you are connecting to. Type “yes” to add the SDC internal GitLab to
the list of trusted hosts.
...
You should see the “Welcome to GitLab, @username!” message.
NOTE: Once added to the list of known hosts, you will not be asked to validate the
authenticity of SDC internal GitLab’s host again. Run the above command once more,
and you should only receive a “Welcome to GitLab, @username!” message.
If the Welcome message does not appear, run SSH in verbose mode by replacing -
T with -vvvT to debug the error:
Code Block |
---|
ssh -vvvT git@scm. internal.sdc.dot.gov |