Let’s say you want to contribute to WordPress. Want to be part of the open-source world and share your skills with the community? For that, you have to clone the WordPress developer version from Github. Now you can do this either using HTTP or the SSH Github key.
Now the question must be asked: do you need a SSH key for Github or will HTTPS be okay? Before we learn the SSH key generation, let’s understand why you need the SSH.
Github HTTP vs SSH
Github has three methods to clone a repository. The third one is Github CLI, which is highly beneficial for production-level automation. But we are talking about you who want to contribute to an open-source project.
That’s why we are going to consider only two: HTTPS and SSH. Let’s see what the differences are between these two.
Aspect | SSH | HTTPS |
---|---|---|
Authentication | Uses SSH keys for secure authentication | Requires a Personal Access Token (PAT) |
Security | Generally considered more secure | Acceptable for basic usage, but not as secure as SSH |
Ease of Setup | Requires initial setup of SSH keys | Simple and straightforward |
Usage | Recommended for regular users and businesses dealing with sensitive data | Suitable for most users and basic Git operations |
Convenience | Uses key files for authentication | Requires entering a password/token for each push |
Port | Typically uses port 22 | Uses port 443 (open in most firewalls) |
From the table, we get an idea of which one is preferred for a more secure connection. The SSH key, which is a large encrypted string that contains letters and numbers, is much more secure. On the other hand, sharing your credentials just to clone a public repo might not be a good idea.
How SSH works on Github
SSH Kye ensures encryption using long strings, as we know already. But it’s not just one, but a pair of keys. In the case of Github, one key is generated for your local system, and another is a public key.
The private key will be stored on your device or on the server that you are connecting to. The public key will be on the Github account through which you will access the other Github repos.
In a nutshell, when you attempt to connect with a repo to clone, the two SSH keys check against each other. The keys match each other, only the connection is established, and you can clone the repository.
SSH key setup for Github
As we are talking about cloning the the WordPress developer version from Github, let try it first. Let’s see what we will see before creating SSH key.
Simple go to the terminal and type,
git-clone [email protected]:WordPress/wordpress-develop.git
After the git clone command, the URL is copied from the wordpress-develop repo on Github. You will see the warning saying you don’t have any public SSH keys in your GitHub account.
After you run the command, this will say the command is not found. Okay, now start creating the SSH key first.
Generating a new SSH key
Our goal here is to create the key in a secure folder called “.ssh.” This will allow the remote server to access the key without asking for the passphrase (which is basically the password) every time.
cd ~/.ssh
Usually the folder will be on your device, but if not, you can create one using the below command and then run the above command.
mkdir ~/.ssh
To create the SSH key on your terminal, type the below command. Please note that this will work on any operating system.
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Change the email to your personal Github account email, by which you will access Github to clone the repo.
Now it will ask for the name of the ID. You can give any name you want. But if you enter the bank, it will be id_rsa by default.
Then it will ask you to enter a passphrase and ask again to confirm.
If everything is correct, then you will see this. With the name of the SSH keys. Yes, it will create two keys: one is private and the other is public. The public one will have the extension .pub in it.
To read these files, you can use the below command. Here my key name is abir-mac. You have to put yours.
Mac and Linux
cat abir-mac
cat abir-mac.pub
Windows
type abir-mac
type abir-mac.pub
Install public key on Github.com
Now let’s add this key to your GitHub account. The process is very simple. Go to the settings in your GitHub account, then go to the SSH and GPH keys.
After that, click on the “New SSH key” and enter the title of the public SSH key file with .pub extension. Now access the .pub version of the key and copy that from the terminal. In the key input section of Github, paste that key and click “add SSH key.” The key type should be “Authentication Key.”
SSH Config
One more thing you have to do if you gave the key a custom name; otherwise, you skip this step. You have to configure the key. To do so, in your terminal, type the below command:
nano config
This will open the configuration interface in the terminal. Now add the below line there.
IdentityFile ~/.ssh/abir-mac
Change the “abir-mac” with your given name here. Now in the MacOS terminal, press Ctrl+X, then press Y and return. The system config file is saved now. That’s it. Now, if you run the git clone again from the terminal, it will definitely start the cloning process.
You can also test it to see if it’s working or not using the below command.
ssh -T [email protected]
Wrap up
Github is a fantastic tool for developers to share their work with others. And that’s not it; as we all know, it is a version control tool for production. But if you can unlock its full potential, you have to ensure security and ease of use. And that’s where the key of SSH GitHub comes in. Happy coding.
Start off with a powerful ticketing system that delivers smooth collaboration right out of the box.
Leave a Reply