Last active
April 4, 2016 09:50
-
-
Save bijayrungta/001a7949c9ccc5f77841294cee2ff9e2 to your computer and use it in GitHub Desktop.
Add Key of a Github User into ~/.ssh/authorised_keys
This file contains 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
#!/bin/bash | |
userDir=bijay | |
githubUser=bijayrungta | |
homeDir=/home/${userDir} | |
mkdir -p ${homeDir}/.ssh | |
if [ f ${homeDir}/.ssh/authorized_keys ]; then | |
echo "User ${userDir} exists with an 'authorized_keys' file" | |
else | |
wget https://github.com/${githubUser}.keys -O /tmp/${githubUser}.keys; | |
txtKey="$(cat /tmp/${githubUser}.keys)" | |
txtKey="${txtKey} ${githubUser}@github" | |
echo ${txtKey} >> ${homeDir}/.ssh/authorized_keys | |
chown -R ${userDir}:${userDir} ${homeDir}/.ssh | |
chmod 700 ${homeDir}/.ssh | |
chmod 600 ${homeDir}/.ssh/authorized_keys | |
fi | |
# Add to sudoers. | |
txtSuders="bijay ALL=(ALL) NOPASSWD: ALL" | |
sudoAccessPresent="" | |
sudoAccessPresent=$(grep -e '^bijay' /etc/sudoers) | |
if [ "${sudoAccessPresent}" ]; then | |
echo "user ${userDir} included in sudoers" | |
else | |
echo "${txtSuders}" >> /etc/sudoers | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment