Step3: Setup SSH Key - SwagatoMondal/Online-Shopping GitHub Wiki

As you might have already noticed, that everytime you login to the remote machine you need to keep entering your password. But you can sip this step forever and setup simple ssh-key based authentication to login securely into your remote machine.

Create your ssh directory

You need to create your ssh directory in the home directory of root machine using the following comamnd -

mkdir -p ~/.ssh

To verify run the following command, and check whether the directory was created.

ls -la

Copying your SSH-Key to Web Server

Now go back to your local machine, and perform the following commands.

Generate Key

In order to generate your public/private RSA key, run the following command -

ssh-keygen -b 4096

You'll be prompted for file & passphrase, which you can leave it to default just by pressing enter or you can customize if required.

Log confirmation

After executing the previous command, you'll notice logs as follows -

Your identification has been saved in /Users/<user-name>/.ssh/id_rsa.
Your public key has been saved in /Users/<user-name>/.ssh/id_rsa.pub.
The key fingerprint is:
// Other details

Add your public key to server

Now you need to copy your public key to the remote machine by running the following command -

scp ~/.ssh/id_rsa.pub <user-name on remote>@<IP Address of remote>:~/.ssh/auth_keys

You'll be prompted for the user password.

Verify copy in remote server

In the remote machine, run the following command to verify the copy -

ls .ssh

Your expected ouptut -

auth_keys

Changing permissions

Now you should alter the permissions for directories so that user(s) have limited privileges.

<user-name>@hostname:~$ sudo chmod 700 ~/.ssh/
[sudo] password for <user-name>: <enter password>
<user-name>@hostname:~$ sudo chmod 600 ~/.ssh/*

Verify

Now we're all set, so run exit command to get back to your local machine. And try running the old command again -

ssh <user-name>@<IP address>

And voila, you won't be prompted for password anymore.

⚠️ **GitHub.com Fallback** ⚠️