Merge pull request #1187 from mslacken/SetSSHKeys

allow the user to specify ssh key types
This commit is contained in:
Christian Goll
2024-05-06 11:12:06 +02:00
committed by GitHub
13 changed files with 98 additions and 20 deletions

View File

@@ -108,6 +108,15 @@ data from other structures.
- Mount: {{ $export.Mount }}
{{- end }}
### SSH
{{- if gt (len .Ssh.KeyTypes) 0 }}
- Key types:
{{- range $index, $keyType := .Ssh.KeyTypes }}
- {{ $keyType }}
{{- end }}
- First key type: {{ index .Ssh.KeyTypes 0 }}
{{- end }}
### Warewulf

View File

@@ -3,12 +3,13 @@
## Automatically configure SSH keys for a user on C SHell login
## Copy this file to /etc/profile.d along with ssh_setup.sh
{{- if gt (len .Ssh.KeyTypes) 0 }}
{{ $keyType := index .Ssh.KeyTypes 0 }}
set _UID=`id -u`
if ( ( $_UID > 500 || $_UID == 0 ) && ( ! -f "$HOME/.ssh/config" && ! -f "$HOME/.ssh/cluster" ) ) then
echo "Configuring SSH for cluster access"
install -d -m 700 $HOME/.ssh
ssh-keygen -t rsa -f $HOME/.ssh/cluster -N '' -C "Warewulf Cluster key" >& /dev/null
ssh-keygen -t {{ $keyType }} -f $HOME/.ssh/cluster -N '' -C "Warewulf Cluster key" >& /dev/null
cat $HOME/.ssh/cluster.pub >>! $HOME/.ssh/authorized_keys
chmod 0600 $HOME/.ssh/authorized_keys
@@ -20,3 +21,6 @@ if ( ( $_UID > 500 || $_UID == 0 ) && ( ! -f "$HOME/.ssh/config" && ! -f "$HOME/
echo " StrictHostKeyChecking=no" >> $HOME/.ssh/config
chmod 0600 $HOME/.ssh/config
endif
{{- else }}
# No ssh key types configured
{{- end }}

View File

@@ -11,12 +11,13 @@
## Automatically configure SSH keys for a user on login
## Copy this file to /etc/profile.d
{{- if gt (len .Ssh.KeyTypes) 0 }}
{{ $keyType := index .Ssh.KeyTypes 0 }}
_UID=`id -u`
if [ $_UID -ge 500 -o $_UID -eq 0 ] && [ ! -f "$HOME/.ssh/config" -a ! -f "$HOME/.ssh/cluster" ]; then
echo "Configuring SSH for cluster access"
install -d -m 700 $HOME/.ssh
ssh-keygen -t rsa -f $HOME/.ssh/cluster -N '' -C "Warewulf Cluster key" > /dev/null 2>&1
ssh-keygen -t {{ $keyType }} -f $HOME/.ssh/cluster -N '' -C "Warewulf Cluster key" > /dev/null 2>&1
cat $HOME/.ssh/cluster.pub >> $HOME/.ssh/authorized_keys
chmod 0600 $HOME/.ssh/authorized_keys
@@ -26,3 +27,6 @@ if [ $_UID -ge 500 -o $_UID -eq 0 ] && [ ! -f "$HOME/.ssh/config" -a ! -f "$HOME
echo " StrictHostKeyChecking=no" >> $HOME/.ssh/config
chmod 0600 $HOME/.ssh/config
fi
{{- else }}
# No ssh key types configured
{{- end }}