Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue Wrong permissions for ssh host private keys on CentOS 7 #2617 #2724

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions xCAT-server/sbin/xcatconfig
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ sub genSSHNodeHostKey
#
# generate new hostkeys
#

my ($rlogin,$rpass,$ruid,$rgid) = getpwnam("root");
my ($sname, $spasswd,$sgid,$smembers)=getgrnam("ssh_keys");
my @sshkeylist;
xCAT::MsgUtils->message('I', "Generating new node hostkeys...");
xCAT::MsgUtils->message('I', "Generating SSH2 RSA Key...");
my $cmd =
Expand All @@ -978,6 +982,10 @@ sub genSSHNodeHostKey
{
xCAT::MsgUtils->message('E', "Could not generate SSH2 RSA key.");
}
else{
push @sshkeylist,"/etc/xcat/hostkeys/ssh_host_rsa_key";
}


xCAT::MsgUtils->message('I', "Generating SSH2 DSA Key...");
$cmd =
Expand All @@ -987,6 +995,9 @@ sub genSSHNodeHostKey
{
xCAT::MsgUtils->message('E', "Could not generate SSH2 DSA key.");
}
else{
push @sshkeylist,"/etc/xcat/hostkeys/ssh_host_dsa_key";
}

# see if this system supports the ecdsa
xCAT::Utils->runcmd('rm -rf /tmp/ecdsa_key >/dev/null 2>&1 ; /usr/bin/ssh-keygen -t ecdsa -f /tmp/ecdsa_key -P "" &>/dev/null', 0);
Expand All @@ -999,8 +1010,17 @@ sub genSSHNodeHostKey
{
xCAT::MsgUtils->message('E', "Could not generate SSH2 ECDSA key.");
}
else{
push @sshkeylist,"/etc/xcat/hostkeys/ssh_host_ecdsa_key";
}
}

if(@sshkeylist){
if(defined $ruid && defined $sgid){
chown $ruid,$sgid,@sshkeylist;
}
chmod 0640,@sshkeylist;
}

# copy the public keys to install directory
$cmd =
Expand Down
13 changes: 8 additions & 5 deletions xCAT/postscripts/remoteshell
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ if [ $? -ne 0 ]; then
getcredentials.awk ssh_dsa_hostkey | grep -v '<'|sed -e 's/&lt;/</' -e 's/&gt;/>/' -e 's/&amp;/&/' -e 's/&quot/"/' -e "s/&apos;/'/" > /etc/ssh/ssh_host_dsa_key
MYCONT=`cat /etc/ssh/ssh_host_dsa_key`
done
chmod 600 /etc/ssh/ssh_host_dsa_key
chown root:ssh_keys /etc/ssh/ssh_host_dsa_key
chmod 640 /etc/ssh/ssh_host_dsa_key
if ! grep "PRIVATE KEY" /etc/ssh/ssh_host_dsa_key > /dev/null 2>&1 ; then
rm /etc/ssh/ssh_host_dsa_key
else
Expand Down Expand Up @@ -215,13 +216,14 @@ if [ $? -ne 0 ]; then
getcredentials.awk ssh_rsa_hostkey | grep -v '<'|sed -e 's/&lt;/</' -e 's/&gt;/>/' -e 's/&amp;/&/' -e 's/&quot/"/' -e "s/&apos;/'/" > /etc/ssh/ssh_host_rsa_key
MYCONT=`cat /etc/ssh/ssh_host_rsa_key`
done
chmod 600 /etc/ssh/ssh_host_rsa_key
chown root:ssh_keys /etc/ssh/ssh_host_rsa_key
chmod 640 /etc/ssh/ssh_host_rsa_key
if ! grep "PRIVATE KEY" /etc/ssh/ssh_host_rsa_key > /dev/null 2>&1 ; then
rm /etc/ssh/ssh_host_rsa_key
else
ssh-keygen -y -f /etc/ssh/ssh_host_rsa_key > /etc/ssh/ssh_host_rsa_key.pub
chmod 644 /etc/ssh/ssh_host_rsa_key.pub
chown root /etc/ssh/ssh_host_rsa_key.pub
chmod 644 /etc/ssh/ssh_host_rsa_key.pub
chown root /etc/ssh/ssh_host_rsa_key.pub
fi
else
#This is an error message
Expand Down Expand Up @@ -286,7 +288,8 @@ if ssh-keygen -t ecdsa -f /tmp/ecdsa_key -P "" &>/dev/null ; then
getcredentials.awk ssh_ecdsa_hostkey | grep -v '<'|sed -e 's/&lt;/</' -e 's/&gt;/>/' -e 's/&amp;/&/' -e 's/&quot/"/' -e "s/&apos;/'/" > /etc/ssh/ssh_host_ecdsa_key
MYCONT=`cat /etc/ssh/ssh_host_ecdsa_key`
done
chmod 600 /etc/ssh/ssh_host_ecdsa_key
chown root:ssh_keys /etc/ssh/ssh_host_ecdsa_key
chmod 640 /etc/ssh/ssh_host_ecdsa_key
if ! grep "PRIVATE KEY" /etc/ssh/ssh_host_ecdsa_key > /dev/null 2>&1 ; then
rm /etc/ssh/ssh_host_ecdsa_key
else
Expand Down