ssh password-less login

We will learn how to login to remote host without entering out password every time.

ssh password-less login

We will learn how to login to remote host without entering out password every time.

Create .ssh directory

The .ssh directory is the default one to save our config file and credentials in it. It is the default path and is picked up by ssh (= it is read). This directory will be (usually) in /home/$USER/.ssh path.

# method one
# execute "mkdir" wherever you are
mkdir -p /home/$USER/.ssh

# method two
# go do home directory then create it
cd ~
mkdir .ssh

Create config file

# after creating ".ssh" directory 
cd .ssh
# or
cd /home/$USER/.ssh
# then create a new file named "config"

# method one
# create an empty file
touch config

# method two
# create an empty file
> config

Up to know we have .ssh and .ssh/config in our home directory

Generate private key and public key

After having .ssh and .ssh/config head to .ssh directory and generate the keys

when running ssh-keygen just hit ENTER and do not type anything

if you be in other directory and not .ssh/ still the ssh-keygen command tries to pick up the right home directory for you and even creating it , as you can see

Transfer you *public key* to the remote host

After using ssh-keygen will have the following

Add your credentials to the config file in .ssh directory

For every login we have to enter our username and remote host's IP Address to mitigate this and automate login for other apps e.g. git push and pull we should config config file

A sample for root users

A sample for non-root users

Set the right permission

If we enter everything right, but do not have the right permission, ssh gives us error and does not work properly.

Test the login to remote host

After configuring config we should be able to login simply by

Make the connection reliable

For keeping the ssh connection we have alive we can add the following to config file

Generate more secure keys to prevent brute-force attack

We can have a more secure keys and prevent brute-force attack using:

  • -a rounds When saving a new-format private key (i.e. an ed25519 key or when the -o flag is set), this option specifies the number of KDF (key derivation function) rounds used. Higher numbers result in slower passphrase verification and increased resistance to brute-force password cracking (should the keys be stolen).

  • -o Causes ssh-keygen to save private keys using the new OpenSSH format rather than the more compatible PEM format. The new format has increased resistance to brute-force password cracking but is not supported by versions of OpenSSH prior to 6.5. Ed25519 keys always use the new private key format.

  • -b bits Specifies the number of bits in the key to create. For RSA keys, the minimum size is 1024 bits and the default is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS 186-2. For ECDSA keys, the -b flag determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will fail. Ed25519 keys have a fixed length and the -b flag will be ignored.

  • -t dsa | ecdsa | ed25519 | rsa

Here is an example of it

Generate custom private key and public key

If we do not want to use id_rsa and id_rsa.pub keys or no, we have them but wanted to have more specific keys, with -f option we can specify the path and name of new file:

when running ssh-keygen just hit ENTER and do not type anything

Last updated

Was this helpful?