Tutorial: ssh: Password less (key based) authentication

Password-less authentication using public/private key pair
Create public/private key pair
Default is RSA key pair for use with SSH v2
It is created in .ssh/ in home directory
Files created are id_rsa (private key file) and id_rsa.pub (public key file)

ssh-keygen -t rsa

Copy public key to remote server .ssh/authorized_keys file
.ssh/ is in the home directory of remote server user (in this case xyz)

cat .ssh/id_rsa.pub | ssh xyz@192.168.1.100 ' \
[ ! -d .ssh ] && mkdir -p -m 700 .ssh ; \
[ ! -f .ssh/authorized_keys ] && touch .ssh/authorized_keys ; \
[ "$(stat -c %a .ssh/authorized_keys)" != 600 ] && chmod 600 .ssh/authorized_keys \
cat - >> .ssh/authorized_keys ; '

Or

cat .ssh/id_rsa.pub | ssh xyz@192.168.1.100 ' \
(umask 0077; [ ! -d .ssh ] && mkdir -p .ssh; \
[ ! -f .ssh/authorized_keys ] && touch .ssh/authorized_keys ; \
cat - >> .ssh/authorized_keys ; )'

Or

ssh-copy-id xyz@192.168.1.100

Leave a comment

Your email address will not be published. Required fields are marked *