Last active
November 24, 2018 09:02
-
-
Save Jaid/c117d9c87dadcd6d4e84c5db6e23901a to your computer and use it in GitHub Desktop.
Setup a new user for remote SSH from client
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
IP_ADDRESS="0.0.0.0" | |
EXISTING_REMOTE_USER=root | |
NEW_REMOTE_USER=user | |
# Authorize as root | |
ssh-copy-id $EXISTING_REMOTE_USER@$IP_ADDRESS | |
# Create user (no interaction needed) | |
echo " | |
adduser --disabled-password --gecos '' $NEW_REMOTE_USER | |
usermod -aG sudo $NEW_REMOTE_USER | |
echo '$NEW_REMOTE_USER ALL=NOPASSWD: ALL' > /etc/sudoers.d/$NEW_REMOTE_USER | |
mkdir /home/$NEW_REMOTE_USER/.ssh | |
cp ~/.ssh/authorized_keys* /home/$NEW_REMOTE_USER/.ssh | |
chown --recursive $NEW_REMOTE_USER /home/$NEW_REMOTE_USER/.ssh | |
" | ssh $EXISTING_REMOTE_USER@$IP_ADDRESS | |
# Start SSH session as new user | |
ssh $NEW_REMOTE_USER@$IP_ADDRESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment