From b48a6c3a57aa25ae396de581d7e276754580bffc Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 13 Jun 2018 20:24:47 -0300 Subject: SSH fixes at kvmx-create --- kvmx-create | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'kvmx-create') diff --git a/kvmx-create b/kvmx-create index 6dc16c9..260b7f5 100755 --- a/kvmx-create +++ b/kvmx-create @@ -447,8 +447,8 @@ EOF # Save host SSH key fingerprints for key in $WORK/etc/ssh/*pub; do - ssh-keygen -l -f $key >> `basename $key`.sha256 - ssh-keygen -l -E md5 -f $key >> `basename $key`.md5 + ssh-keygen -l -f $key >> $sshdir/`basename $key`.sha256 + ssh-keygen -l -E md5 -f $key >> $sshdir/`basename $key`.md5 done # Sudo @@ -464,36 +464,39 @@ EOF kvmx_sudo_run chroot $WORK/ useradd $user -G sudo -s /bin/bash fi - if [ "$ssh_support" == "y" ]; then - if [ "$ssh_custom" == "y" ]; then - if [ ! -z "$ssh_custom_pubkey" ]; then - pubkey="$sshdir/ssh/$hostname.key.pub" + # Initial user homedir + mkdir -p $WORK/home/$user - if [ -e "$ssh_custom_pubkey" ]; then - cp $ssh_custom_pubkey $pubkey - else - echo $ssh_custom_pubkey > $pubkey - fi + #if [ "$ssh_support" == "y" ]; then + if [ "$ssh_custom" == "y" ]; then + if [ ! -z "$ssh_custom_pubkey" ]; then + pubkey="$sshdir/ssh/$hostname.key.pub" + + if [ -e "$ssh_custom_pubkey" ]; then + cp $ssh_custom_pubkey $pubkey else - privkey="$sshdir/ssh/$hostname.key" - pubkey="${privkey}.pub" - __kvmx_ssh_keygen $privkey "$user@$hostname" + echo $ssh_custom_pubkey > $pubkey fi else - pubkey="$DIRNAME/share/ssh/insecure_private_key.pub" + privkey="$sshdir/ssh/$hostname.key" + pubkey="${privkey}.pub" + __kvmx_ssh_keygen $privkey "$user@$hostname" fi + else + pubkey="$DIRNAME/share/ssh/insecure_private_key.pub" + fi - kvmx_sudo_run chroot $WORK/ mkdir -p /home/$user/.ssh - kvmx_sudo_run chroot $WORK/ chmod 700 /home/$user/.ssh - kvmx_sudo_run cp $pubkey $WORK/home/$user/.ssh/authorized_keys - kvmx_sudo_run chroot $WORK/ chmod 600 /home/$user/.ssh/authorized_keys - kvmx_sudo_run touch $WORK/home/$user/.hushlogin + kvmx_sudo_run chroot $WORK/ mkdir -p /home/$user/.ssh + kvmx_sudo_run chroot $WORK/ chmod 700 /home/$user/.ssh + kvmx_sudo_run cp $pubkey $WORK/home/$user/.ssh/authorized_keys + kvmx_sudo_run chroot $WORK/ chmod 600 /home/$user/.ssh/authorized_keys + kvmx_sudo_run touch $WORK/home/$user/.hushlogin - # Cleanup temporary file if needed - if [ ! -z "$ssh_custom_pubkey" ]; then - rm $pubkey - fi + # Cleanup temporary file if needed + if [ ! -z "$ssh_custom_pubkey" ]; then + rm $pubkey fi + #fi kvmx_sudo_run chroot $WORK/ chown -R $user.$user /home/$user echo "$user:$password" | kvmx_sudo_run chroot $WORK/ chpasswd -- cgit v1.2.3