Fix a bug with public keys being added to root. Made public key process clearer to the user
This commit is contained in:
parent
dd7d089489
commit
25bd635c4e
15
InitMate.sh
15
InitMate.sh
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
LOG_FILE="$(dirname "$0")/setup.log"
|
LOG_FILE="$(dirname "$0")/setup.log"
|
||||||
|
ORIGINAL_USER=$(logname)
|
||||||
|
|
||||||
# ASCII Art Banner
|
# ASCII Art Banner
|
||||||
cat << "EOF"
|
cat << "EOF"
|
||||||
|
@ -101,13 +102,15 @@ secure_ssh() {
|
||||||
sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config
|
sed -i "s/#PasswordAuthentication yes/PasswordAuthentication no/" /etc/ssh/sshd_config
|
||||||
sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config
|
sed -i "s/#PubkeyAuthentication yes/PubkeyAuthentication yes/" /etc/ssh/sshd_config
|
||||||
|
|
||||||
log "Please enter your public key:"
|
log "Please enter your public key (this is for your current user.):"
|
||||||
read -r PUBLIC_KEY
|
read -r PUBLIC_KEY
|
||||||
|
|
||||||
mkdir -p ~/.ssh
|
sudo -u "$ORIGINAL_USER" bash -c "
|
||||||
echo "$PUBLIC_KEY" > ~/.ssh/authorized_keys
|
mkdir -p ~/.ssh
|
||||||
chmod 600 ~/.ssh/authorized_keys
|
echo '$PUBLIC_KEY' > ~/.ssh/authorized_keys
|
||||||
chmod 700 ~/.ssh
|
chmod 600 ~/.ssh/authorized_keys
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
"
|
||||||
|
|
||||||
systemctl restart sshd
|
systemctl restart sshd
|
||||||
}
|
}
|
||||||
|
@ -199,7 +202,7 @@ add_users() {
|
||||||
if prompt_yes_no "Do you want to add a public key for $USERNAME?"; then
|
if prompt_yes_no "Do you want to add a public key for $USERNAME?"; then
|
||||||
log "Please enter the public key:"
|
log "Please enter the public key:"
|
||||||
read -r PUBLIC_KEY
|
read -r PUBLIC_KEY
|
||||||
su - "$USERNAME" -c "mkdir -p ~/.ssh && echo '$PUBLIC_KEY' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh"
|
sudo -u "$USERNAME" bash -c "mkdir -p ~/.ssh && echo '$PUBLIC_KEY' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh"
|
||||||
log "Public key added for $USERNAME."
|
log "Public key added for $USERNAME."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user