Public keys best practice question

Hi everyone,

I am setting up a yum update server using the script below kindly provided by andreas.

My question is what is the best way to distribute the public key from the central Distribution server to all the client servers. The central distro server is a RHEL server.

Can the public key belong to the root user or should it be another key for just yum updates.


#!/bin/bash
hosts=$(cat $1)
for i in $hosts ;do
ssh root@$i -t sudo '/usr/bin/yum update -y'
done
then call script with
./scriptname filename.txt
filename.txt should have one ip in one line
each line one ip
LVL 1
Peter KuczynskiLead Cloud EngineerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
andreasConnect With a Mentor System AdminCommented:
when you access the server you need ROOT. but ON the central server you dont.

so on central server you setup a user called

update


there in /home/update/.ssh/ you create the ssh keys as usual.

then you copy the public key file to the client server to the root accounts authorized_keys file

you can use the ssh-copy-id command for this:

ssh-copy-id root@clientserver1

afterwards you should be able to run ssh root@clientserver1 without password.

then you can call the script, as you are connecting as root you can skip the sudo on the central server
0
 
andreasSystem AdminCommented:
To copy the keys you can use the command

ssh-copy-id command. You need to enter the password of the target server once for installing the pub key on the client server.

You can run the coordination of this from a user account in the update server which has its own key, it doesnt need to be the root account. As a rule of thumb its always recommended to do as much things as a user as possible and use roor only when really necessary only.

So use own account + own priv/pub-key piar for the logons on the clients.

Its NOT necessary to have one key per client server. If your central server gots hacked you have other problems. If the clients get hacked the pub key ther eis useless for the attacker. It wont enable him to access other systems or your central update server.
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
Not working as a regular user.
I copied the public key to a test server, which I previously copied the root public key to as well.
This time it's under a user account/home/testuser1/.ssh/authorized_keys

I ran the above script and I am being prompted for a root password.

When I run it as root, it just installs the updates.
0
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
oh I cant believe I did this, see the script shows root@ ? I changed it to the user ID now it runs : )
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
how would I trap the hostname of the server I'm connecting to in the script

#!/bin/bash
hosts=$(cat $1)
for i in $hosts ;do
ssh ec2-user@$i -t sudo '/usr/bin/yum update -y' >> logs
done

So the script pipes out the updates that were run, but it dosnt show what server they were run on, anyway to do that?
0
 
andreasSystem AdminCommented:
just add an echo line infront of the ssh command in the script.
Just add

echo $i >> logs

and you have the ip b4 the yum log
0
 
gheistCommented:
What are you distributing?
SSH public key or YUM/RPM signing key?
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
I am initially wanting to trigger yum updates on my servers which will be in the hosts file.
I also need to reset root passwords on the client servers.

Eventually, I want to be able to implement yum updates from my own repository.
So as a first step, I need to get the public key from the central server out to all the client servers.
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
Andreas ,I"ll be implementing this today, let me get back to you then, and thanks!
0
 
gheistCommented:
You can use spacewalk or any configuration management solution like puppet to do that.
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
Andreas,
I created a "update" user on the central server, and the keys then added the .pub key to the target server,
the script now works.
I would just like to fix logging
When I add echo $i >> logs the script does not run

#!/bin/bash
hosts=$(cat $1)
for i in $hosts ;do
ssh root@$i -t sudo '/usr/bin/yum update -y' echo $i >> logs
done
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
this seems to work, it creates a log and sorts it by ip address and date

#!/bin/bash
hosts=$(cat $1)

for i in $hosts ;do

ssh root@$i -t sudo '/usr/bin/yum update -y' >> logs/"$i"log.`date +%d`


done
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
One last question, how can I change this script to update just a single package, as in the case with recent ssl package vulnerability
0
 
gheistCommented:
You need to restart all services that has it open...
ssh x@y "yum upgrade -y openssl"
With "recent" ssl vulnerability aka POODLE you had to reconfigure all SSL-aware software to avoid using SSLv3.
0
 
Peter KuczynskiLead Cloud EngineerAuthor Commented:
great thanks!
0
 
gheistCommented:
You can dig some ideas from centos-announce mailing lists.
What I wanted to say:
if you upgrade openssl - it is still loaded by openssh, apache, ftpd, anything, so you have to politely restart them all/
if you disable SSLv3 in configuration obvioulsy you need to restart that service.

On the other hand debian and behind its tail ubuntu completely disabled SSLv3 already by now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.