SSH (Secure Shell) is a network protocol used to securely connect and communicate with remote computers over an unsecured network. It provides a secure encrypted communication channel between two untrusted hosts over an insecure network. SSH is widely used by system administrators, developers, and power users to remotely manage and access their systems and data. SSH uses a client-server model, where the client establishes a secure connection to the server and can then send and receive data through that connection. The server typically runs an SSH daemon, which listens for incoming connections on a specific TCP/IP port. The client must have an SSH client software installed on their local computer to initiate the connection. Once the connection is established, the user can perform various tasks such as executing remote commands, transferring files, and tunneling other network protocols through the secure connection. SSH is widely considered to be a more secure alternative to traditional remote login protocols like Telnet, which transmit data in clear text over the network.
For our case the remote computer or server is github.com and the client is us.
Note: Make sure that you have already configured git before proceeding.
You can configure git using the following commands:
Make sure that you don't include the quotes unless your name has spaces. If you opted to use a private email use it instead of your actual one.
git config --global user.name "Your Name" # For your name [only include the quotes if you are using more than one name/word]
git config --global user.email "Your Email" # For email (use the generated if you opted for private email it will look something like this "[email protected]") [Don't include the quotes]
Verify if your details are correct by using the following commands
git config --get user.name # To check your username
git config --get user.email # To check your email
Now let's get to configuring SSH.
First let's see if we have SSH key in our machine
ls ~/.ssh/id_ed25519.pub
We'll use ED25519 because of its security and speed advantages. You can read more about it here
If the message from the above command is No such file or directory
then we have to create a new one, if it is there then you can skip this part.
NOTE:
If you already have an ssh key in your machine, and it is being used, don't overwrite it. Instead, give a different path in the ssh folder so as to avoid conflicts.
Use the following command to generate a new SSH key
ssh-keygen -t ed25519 -C "Your email"
- If it prompts you for a location to save just press
Enter
- Next, it will prompt you for a password. You can choose to enter one or not, it is not mandatory
Now let's copy the contents of the file so that we can store them in Github. This will tell Github who we are and remove the need to reauthenticate every time we have to push our code to Github.
cat ~/.ssh/id_ed25519.pub
Make sure you are logged in to Github before continuing with the following steps.
First, you’ll navigate to where GitHub receives our SSH key. Click on your profile picture in the top right corner. Then, click on Settings in the drop-down menu.
Next, on the left-hand side, click SSH and GPG keys. Then, click the green button in the top right corner that says New SSH Key. Name your key something that is descriptive enough for you to remember where it came from.
Now paste the contents of the cat ~/.ssh/id_ed25519.pub
command that we performed earlier into the key field. The contents should end with your email address.
Click on Add SSH key
and voila! you are done!
Follow the instructions here to test if your key was successfully added to Github