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
.ssh directoryThe .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 .sshCreate config file
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
> configGenerate private key and public key
After having .ssh and .ssh/config head to .ssh directory and generate the keys
I ran the ssh-keygen as root on my Linux machine so my home directory is /root and yours will be different if you were not root user.
If you already had the default keys id_rsa and id_rsa.pub the will be overwritten! So have the backup of previous ones if you re-generated them.
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
config file in .ssh directoryFor 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
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:
-arounds 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).-oCauses 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 bitsSpecifies 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:
Last updated
Was this helpful?