I have several Red Hat 7 servers which I am attempting to copy over the ssh keys from a “root” server. This server will allow passwordless ssh logins by sharing this key. The problem I am facing is not all the servers have a /root/ssh directory so when I try to just echo the key information into authorized_keys file it fails.Is there a way I can create a fixlet that if the /root/ssh directory doesn’t exist to create it first then echo the key information into the newly created authorized_keys file? Or is there a better method to do this with BigFix?
In short I am just trying to copy over the contents of id_rsa.pub so I can use this single linux server to connect to any of my other RHEL servers from this box. Root ssh is disabled on most of them so I can’t just run ssh-copy-id . I thought about creating a fixlet to enable root ssh to run that, not sure how I could do this with BigFix, then disable root ssh again.
// paste public key to be pushed
action parameter query “ssh_key” with description “paste public key”
//create .ssh dir if not exists
if {not exists folder “/root/.ssh”}
folder create "/root/.ssh"
endif
// command line-fu
delete __appendfile
appendfile /bin/echo “{parameter “ssh_key” of action}” >> "/root/.ssh/authorized_keys"
wait chmod 500 "{(client folder of current site as string) & “/__appendfile”}
wait /bin/sh “{(client folder of current site as string) & “/__appendfile”}”