Last active
June 24, 2016 16:24
-
-
Save romuloceccon/1a6fa6aeb71f560a3244100aa8a7cc05 to your computer and use it in GitHub Desktop.
Initialize the .ssh dir of a user using credentials from another user (with root privileges)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copy and paste the following lines into a shell replacing $1 with the actual username. | |
| # It will then ask for the public key to initialize the .ssh dir. | |
| # The key will be appended to the authorized_keys file; current content (if any) will be preserved. | |
| U=$1 ; H=$(eval echo ~$U) ; sudo mkdir -p $H/.ssh \ | |
| && echo "Paste ssh key: (end with ^D)" \ | |
| && cat > /tmp/$U_key.pub \ | |
| && cat /tmp/$U_key.pub | sudo tee -a $H/.ssh/authorized_keys > /dev/null \ | |
| && rm /tmp/$U_key.pub \ | |
| && sudo chown $U:$U $H/.ssh \ | |
| && sudo chmod 700 $H/.ssh \ | |
| && sudo chown $U:$U $H/.ssh/authorized_keys \ | |
| && sudo chmod 600 $H/.ssh/authorized_keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment