Ask Your Question

is it possible for me to purge specific ssh key from the list of keys in .ssh/authorized_keys file?

asked 2016-03-31 12:15:15 -0500

shagone gravatar image

I would like to purge only few specific ssh keys from the list of all the keys in authorized_keys file on the agent using puppet master. I tried using purge resource, but all the keys in authorized keys file are being purged. Is there a way to purge only few specific ones?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-31 14:11:43 -0500

updated 2016-03-31 14:18:35 -0500

Are you managing this as the whole file with the file resource type something like this?

file { '/home/binky/.ssh/authorized_keys':
  ensure  => 'absent',

If so you might want to look at using the sshauthorizedkey resource type which can manage each entry as a single resource and ensure can only be present or absent

ssh_authorized_key { '':
  ensure => present,  ### or absent,
  user => 'binky',
  type => 'ssh-rsa',
  key  => 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDG3D2AdERHzRtdswPBqkOFyqpOoNah8ll1U8SlrY2wus5SiS3PO07B5hnkaACz9vPcBsusoqOt7KN+JUE2z9KeN1/Xvyl1MyflikbJfWUAMQLg3zkJ30y3sbRQHa7EPQ59Zc3VUQSxDSqr/iCbEWitIw5lVTItspF9fYq+R7/wZIELFhN/6I9/fOew65K8/ky9rrSUQKLpapLPN+02ema/BkfDM+j4U4H2zbK06abGdLUABDwj8sQILocG3U6mF9m/3yQezdOEBn0n3oELK15034BiSdwc6TgEneyLoSiCULA0swbmU1CSRRrO59TVS109SEaGIrtEH275IhYPZWqp',


edit flag offensive delete link more


Thanks for the reply Binky. I tried using this, but this is purging all the keys in the authorized_keys file along with the specified key.

shagone gravatar imageshagone ( 2016-03-31 18:18:24 -0500 )edit

That is odd. Although when I was playing with this last night I couldn't work out how to run puppet resource ssh/_authorized/_key because some how one needs to specify the key and either the file it's self or at least which user it belongs to.

Binky gravatar imageBinky ( 2016-04-01 03:27:12 -0500 )edit

OK could you post your resource definition for the key? Change the key to something rubbish if you like I'm just curious to see if I can replicate the problem. I managed to get puppet resource to list my key like this puppet resource ssh_authorized_key binky user=ubuntu

Binky gravatar imageBinky ( 2016-04-01 03:53:54 -0500 )edit
Binky gravatar imageBinky ( 2016-04-01 03:55:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-03-31 12:15:15 -0500

Seen: 92 times

Last updated: Mar 31 '16