Login with SSH without password by Puppet-manifest

With puppet it's fairly easy to login from HostA to remote HostB when using SSH.

First create a SSH public/private key pair on HostA like so:

$ sshkeygen -t rsa -f name-of-your-key

This generates:


Now connect to the remote HostB and create a .ssh folder in the home-folder (if it not already exists):

$ mkdir -p ~/.ssh

Logout again.

Now, from local HostA run this command to append your public key to authorized_keys on the remote HostB:

$ cat .ssh/name-of-your-key.pub | ssh b-user@HostB 'cat >> .ssh/authorized_keys'

Also create locally this file in ~/.ssh/config:

Host HostB
    Hostname HostB
    Port 22
    User b-user
    IdentityFile ~/.ssh/name-of-your-key

Now you can login like so:

$ ssh HostB

What's the puppet manifest for this?

# contents of ssh_userb.pp
ssh_authorized_key {'user-b':
    ensure => 'present',
    key    => 'verylongkey-sdisjklshfjdklsfjssjklASJDLDkj$'
    type   => 'rsa',
    user   => 'user-b',

Where the value of key is the value found in name-of-your-key.pub without the "ssh-rsa" prefix and the name suffix.

You can now apply this puppet manifest like so on the remote HostB:

$ puppet apply /path/to/ssh_userb.pp