I'm trying to add a key to /root/.ssh/authorized_keys(it has chmod 600) using puppet.
I use ssh_authorized_key resource for this.
ssh_authorized_key { 'my@mail.com':
ensure => present,
user => 'root',
type => 'ssh-rsa',
key => 'myKey',
}
When I run puppet apply ... as root for the first time it throws this error:
"Error: Puppet::Util::FileType::FileTypeFlat could not write /root/.ssh/authorized_keys: Permission denied - /root/.ssh/authorized_keys",
Nevertheless it adds the above key to /root/.ssh/authorized_keys but removes all existing keys. If I run it second time it completes successfully without any errors.
What can cause such strange behavior and how can I fix this? (My OS is CentOS 6)