parent
0f2d304f4c
commit
5a6c8229c6
@ -1,12 +1,21 @@ |
|||||||
#!/bin/sh |
#!/bin/sh |
||||||
|
|
||||||
if [ "$(id -u)" -ne 0 ]; then |
# This if statement evaulates if the script is launched using sudo AND not |
||||||
echo "This script should be run as root. Aborting..." > /dev/stderr |
# a `sudo su` logged user |
||||||
exit 1 |
if [ -n "$SUDO_USER" ] && [ "$SUDO_COMMAND" != "/usr/bin/su" ]; then |
||||||
fi |
|
||||||
|
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..." |
echo "Creating SSH key..." |
||||||
ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa |
ssh-keygen -t rsa -b 4096 -q -N "" -f ~/.ssh/id_rsa |
||||||
|
|
||||||
echo "Adding SSH key to authorized..." |
echo "Adding SSH key to authorized..." |
||||||
cat ~/.ssh/rsa.pub >> ~/.ssh/authorized_keys |
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys |
||||||
|
|
||||||
|
fi |
||||||
|
Loading…
Reference in new issue