- [Instructor] In the previous video,
we looked at how to transfer files through the network.
The name of this video is Password-Less Auto-Login with SSH.
This video describes how to create ssh keys
and facilitate auto-login.
SSH is widely used with automation scripting
as it makes it possible to remotely execute commands
at remote hosts and read their outputs.
Usually SSH is authenticated by using a username
and password which are prompted during
the execution of SSH commands.
However, providing passwords in automated scripts
is impractical so we need to automate logins.
SSH has in-built feature by which
SSH can auto-login using SSH keys.
SSH uses an encryption technique called asymmetric keys
consisting of two keys, a public key and a private key
for automatic authentication.
We can create authentication key pair
using the ssh-keygen command.
For automating the authentication,
the public key must be placed at the server
by appending the public key to the authorized_keys file
and the private key of the key pair should be present
at the .ssh directory of the user at the client machine.
Which is the computer you are logging in from.
Several configurations, for example the path name
of the authorized_keys file regarding the SSH,
can be configured by altering
the configuration in sshd_config.
There are two steps towards setup
of automatic authentication with SSH.
They are, creating the SSH key on the machine
which requires a login to the remote machine.
Transferring a public key generated to the remote host
and appending it to ~/.ssh/authorized_keys.
In order to create an SSH key enter the ssh-keygen command
with the encryption algorithm.
Type specified as RSA like so.
You may need to enter a passphrase
for generating the public-private key pair.
It's also possible to generate the key pair without
entering a passphrase but it's insecure.
We can write monitoring scripts that use
an automated login from the script to several machines.
In such cases you should leave the passphrase empty
while running the ssh-keygen command to prevent the script
from asking for a passphrase while running.
As you can see, the key has now been created.
Now, id_rsa.pub and id_rsa have been generated.
id_pub is the generated public key
and id_rsa is the private key.
Nice!
The public key has to be appended
to the authorized_keys file on remote servers
where we need to auto-login form the current host.
In order to append the key file use this command.
Provide the login in the previous command.
The auto-login has been setup and from now onwards
SSH will not prompt for password during execution.
Test this with the command.
You will not be prompted for a password.
Most Linux distros ship with a tool called shh-copy-id,
which will automatically add your private key
to the authorized_keys file on the remote server.
Use it like this.
Cool!
In this video, we've facilitated
password-less auto-login with SSH.
In the next video, we'll dive into
port forwarding using SSH.