Copy SSH Keys from Central server to all other Linux servers

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.

Greetings.

You could always put something like this into your actionscript:

if {not exists folder “/root/.ssh”}
folder create "/root/.ssh"
endif

If I use that what would the BigFix actionscript equivalent look like? I am still trying to figure all this stuff out.

I was planning on using a one liner sh script -
#!/bin/sh
echo “ssh-rsa {all sorts of goofy characters here root@” >> /root/.ssh/authorized_keys

Would I do the create file and then move file method using BigFix actionscript?

So it would look something like this:
if {not exists folder “/root/.ssh”}
folder create "/root/.ssh"
endif

appendfile #!/bin/sh
appendfile echo “ssh-rsa {all sorts of goofy characters here root@” >> /root/.ssh/authorized_keys
move __appendfile auth_keys.sh
run chmod 777 auth_keys.sh
wait sh auth_keys.sh

This should work:

// 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”}”

2 Likes

That did the trick! Thanks again for the assistance.

1 Like