How to automate SSH login with password?

How to automate SSH login with password?

Method 1:

Here is the steps to generate passphraseless SSH key

Generate a passphraseless SSH key and push it to your other machine.

If you already have an SSH key, you can skip this step… Just hit Enter for the key and both passphrases:

$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/

Copy your keys to the target server:

$ ssh-copy-id id@server
id@server's password: 

Now try logging into the machine, with ssh 'id@server', and check in:


to make sure we haven’t added extra keys that you weren’t expecting.

Finally check logging in…

$ ssh id@server


Method : 2

All the following commands are being run on the client side, i.e. your machine

Enter the following command to start generating a rsa keypair:

# ssh-keygen

When the message ‘Enter file in which to save the key’ appears, just leave the filename blank by pressing Enter.

When the terminal asks you to enter a passphrase, just leave this blank too and press Enter.

Then copy the keypair onto the server with one simple command:

# ssh-copy-id userid@hostname

you can now log in without a password:

# ssh userid@hostname