You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
601 B
21 lines
601 B
#!/bin/sh
|
|
|
|
# This if statement evaulates if the script is launched using sudo AND not
|
|
# a `sudo su` logged user
|
|
if [ -n "$SUDO_USER" ] && [ "$SUDO_COMMAND" != "/usr/bin/su" ]; then
|
|
|
|
echo "Creating SSH key..."
|
|
su -c 'ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa' "$SUDO_USER"
|
|
|
|
echo "Adding SSH key to authorized..."
|
|
su -c 'cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys' "$SUDO_USER"
|
|
|
|
else
|
|
|
|
echo "Creating SSH key..."
|
|
ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa
|
|
|
|
echo "Adding SSH key to authorized..."
|
|
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
|
|
|
|
fi
|
|
|