Table of Contents |
---|
Setting Up SDC with GitLab Repositories
...
🔑 Generate SSH Key
To set up git Git integration, you need to have an SSH key on your SDC workstation. This key
authenticates your identification to GitLab so that you can push commits to the project
repository.
To store your Your key authentication credentials for git, use are, by default, stored in a hidden folder called named “.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:
You’ll need to ensure this folder exists in your home directory before creating your key.
This can be done using Git Bash (for Windows), as below.
a. Open the Git Bash application from the Windows search box:
i. In the search box, type ‘Git Bash’ and hit enter.
ii. Then, click on Git Bash App listed under the Best Match heading.
b. The Git Bash terminal opens and should be active within your home directory.
The title bar of the terminal window will display MINGW64/c/Users/<your-SDC-username>,
where <your-SDC-username> is your actual SDC user credential.
c. Use Git Bash to check if the .ssh folder already exists in your home directory:
At the $ prompt, type the following command and then hit enter.Code Block ls-a
This will list all objects in your home directory.
d. Confirm whether you see the .ssh folder listed in the results:
e. If not found, then create the .ssh folder:
At the prompt, type the following and then hit enter.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:f. Confirm the .ssh folder is now created:
At the prompt, type the following and then hit enter.
GenerateCode Block ls –a
-a
Next, use Git Bash to generate a new SSH key to and store in this location by typing it in the .ssh folder.
a. Generate the key pair:
At the prompt, type the following command and then hitting the Enter key:* and then hit enter
Code Block ssh-keygen -t rsa -b 4096 -C "<your-SDC-username@dot.gov>"
*NOTE: Be sure to replace <your-SDC-username@dot.gov> with your SDC email address,
or other email address/ identifier of your choosing.
b. It will output the following message: “Generating “Generating public/private rsa key pair.”
c. It will then 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 prompt “Enter file in which to save the key:”
At the prompt, type the following and hit enter.Code Block C:\Users\<your-SDC-username>\.ssh\id_rsa
d. It will also ask you to enter a passphrase with the following 2 prompts.
• “Enter passphrase (empty for no passphrase):”
• “Enter same passphrase again:”
After the following confirmation messages, Hit the Enter key each time (no need to enter anything else) to accept the defaults.
e. The following messages confirm the new SSH key is now stored in the .ssh
folder.
• “Your identification has been saved in /c/Users/SDCusername/C:\Users\<SDCusername>\.ssh/\id_rsa.”
• “Your public key has been saved in /c/Users/SDCusername/C:\Users\<SDCusername>\.ssh/\id_rsa.pub.” The default key file name is id_rsa and is
NOTE: Your SSH key pair is comprised of two files, which have been saved under the .ssh folder (e.g.,
in your home directory ( C:/Users/[SDCusername]<your-SDC-username>/.ssh/ in Windows; $HOME/.ssh/id_rsa in Linux)) .
The private identification is saved in the id_rsa file and the public part of the key is saved in the id_rsa.pub file.
3. You now need to provide the
...
‘public’ part of this key to GitLab
...
:
In the Git Bash terminal, type the following command at the prompt, and then hit enter.
Code Block |
---|
cat ~/.ssh/id_rsa.pub | |
...
cli |
This copies the content of id_rsa.pub to your clipboard.
4. Next, open GitLab, and on the GitLab home page, you’ll 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
...
the email that you provided in step##
<your_sdc_username@dot.gov>.
e. Click the Add key button.
5. To test whether your SSH key was added correctly,
...
type the following command, in your
...
Git Bash terminal,
and then hit enter:
Code Block |
---|
ssh -T |
...
git@gitlab.prod.sdc.dot.gov |
a. 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.
b. You should see the “Welcome to GitLab,
...
@SDCusername!” 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,
...
@SDCusername!” message.
c. If the Welcome message does not appear,
...
rerun the last command in ‘verbose’
mode by replacing -T with -vvvT. This will return more details that can be used to help debug the
error
...
.
Code Block |
---|
ssh -vvvT |
...
git@internal.sdc.dot.gov |