Search code examples
sshautomationpasswords

Have password automatically entered when ssh


From my laptop, I often ssh into another machine in my university department. I have to put in a password every time currently.

Could someone give me an idiot's guide to having the password be automatically entered each time I log in please.

Thank you in advance.


Solution

  • You can override by enabling Password less authentication. But you should install keys (pub, priv) before going for that.

    Execute the following commands at local server.

    Local $> ssh-keygen -t rsa 
    

    Press ENTER for all options prompetd. No values need to be typed.

    Local $> cd .ssh
    Local $> scp .ssh/id_rsa.pub user@targetmachine:
    Prompts for pwd$>  ENTERPASSWORD
    

    Connect to remote server using the following command

    Local $> ssh user@targetmachine
    Prompts for pwd$> ENTERPASSWORD
    

    Execute the following commands at remote server

    Remote $> mkdir .ssh
    Remote $> chmod 700 .ssh
    Remote $> cat id_rsa.pub >> .ssh/authorized_keys
    Remote $> chmod 600 .ssh/authorized_keys
    Remote $> exit
    

    Execute the following command at local server to test password-less authentication. It should be connected without password.

    $> ssh user@targetmachine