Monday, February 10, 2014

How to ssh/sftp/scp a remote server without password prompt?

Without password prompt when you access a remote server, transfer files to or from a remote server or copy files to a remote server is very meaningful to execute some tasks over a shell script between several servers.
Assuming you want A to access B
1. Using ssh-keygen to generate public and private keys

NAME
     ssh-keygen — authentication key generation, management and conversion.

Don't put pass-phrase, just type an enter when it asks you "Enter pass-phrase" otherwise it will still prompt you to key in pass-phrase when it connects.

2. Using ssh-copy-id to install your public key to remote server

NAME
       ssh-copy-id - install your public key in a remote machine's authorized_keys.

Type
~$ ssh-copy-id -i ~/.ssh/id_rsa.pub <username>@<host_ip>

Then test ssh, sftp and scp.



No comments:

Post a Comment