Protocols govern the methods and rules for data transmission, and Git uses several protocols to transfer data between repositories. Here are the main ones:
Local Protocol: Used when both the source and destination repositories are on the same filesystem. Data is transferred by simple file copying.
HTTP/S Protocol: Allows Git to communicate over HTTP or HTTPS. Commonly used for public-facing repositories, as it can be easily secured with SSL.
SSH Protocol: Secure Shell (SSH) is a secure way to transfer data. It requires authentication and is often used in corporate environments where security is a priority.
Git Protocol: A special daemon that comes with Git, listening on a dedicated port (9418). It is a fast but unauthenticated protocol, making it suitable for read-only access to repositories.
Each of these protocols has its own use cases and advantages, depending on the security and performance requirements of the environment.
SSH is considered more secure than entering credentials over HTTPS, making it the preferred choice for businesses handling sensitive and critical data. By generating SSH keys, you ensure that only machines with the key file on disk can access the repository.
Utilizing an SSH key offers a convenient and secure method to access your account. It eliminates the need to remember a complex password, allowing you to create an exceptionally long and secure password that is virtually impossible for humans or bots to guess. The SSH key functions as a unique key, granting access solely to you.
To use an SSH key with Git, you must first create the key on your computer. If you already have an SSH key, you can skip these steps. To check if you have a key, run this command:
ssh-add -l
username@servername:
Specifies the user and the server you are trying to access.
username
is the account name you use to log into the remote server.servername
is the hostname or IP address of the remote server.#
Typically represents a command prompt in a Unix-like operating system, indicating administrative privileges (root or sudo user).
ssh-add -l:
ssh-add
is a utility for adding private key identities to the SSH authentication agent, which manages your private keys and can provide them to SSH clients on demand.-l
option stands for "list" and instructs ssh-add
to list the identities (private keys) currently stored in the SSH agent.Putting it all together, the command ssh-add -l
lists the SSH keys managed by the SSH agent on your local machine.
Follow these steps to create the key and copy its contents. You will need to open your computer’s terminal application.
Step 1: Open the terminal app on your computer.
Step 2: Enter the following command, substituting useremail@example.com
with your email address:
ssh-keygen -t rsa -b 4096 -C "useremail@example.com"
Step 3: Press Enter to accept the default file location.
Step 4: Enter a secure passphrase.
Step 5: Press Enter.
Step 6: Enter this command to display the contents of your public key:
cat .ssh/id_rsa.pub
Step 7: Copy the contents of your key to your clipboard (we will need it later).
Note: It's crucial to understand that an SSH key consists of two components: a private key and a public key. The private key should remain confidential and never be shared, except under specific circumstances such as with your system administrator or other trusted individuals within your organization. Safeguarding your private key is essential for maintaining security.
We've already explored the benefits of using SSH keys and have shown you how to generate an SSH key pair on your computer. Now, let's go through the process of uploading your public key to GitHub.
Step 1: Log into your GitHub account.
Step 2: Click your avatar and choose Settings.
Step 3: Select SSH and GPG keys.
Step 4: Click New SSH key.
Step 5: Enter a title in the field.
Step 6: Paste your public key into the Key field.
Step 7: Click Add SSH key.
Congratulations! You now know how to add SSH keys to your GitHub account.
If you haven't pre-registered for a JuniorIT.AI membership, please do so now at https://juniorit.ai/auth/pre-register. All pre-registered members will receive a one-year free membership for a limited time.
Please subscribe to our official YouTube Channel for more courses: JuniorIT YouTube.
Acquire the essential skills and knowledge to kickstart your career and set off on a new path in the age of AI.