Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Last active July 25, 2023 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SanariSan/7fe69763459b333232e09e255de03170 to your computer and use it in GitHub Desktop.
Save SanariSan/7fe69763459b333232e09e255de03170 to your computer and use it in GitHub Desktop.
ssh create user+key
# ssh to server
# ---
# add new user
sudo adduser user
# usermod -aG sudo user
# gpasswd -d user sudo
su - user
# ---
# on new user
# create key and key.pub
mkdir -p $HOME/.ssh
chmod 0700 $HOME/.ssh
touch $HOME/.ssh/authorized_keys
chmod 600 $HOME/.ssh/authorized_keys
ssh-keygen -t rsa -b 4096 -f ~/.ssh/key
cat ~/.ssh/key.pub >> ~/.ssh/authorized_keys
cat ~/.ssh/key # copy
# ---
# switch login by pkey + passwd
echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
echo 'AuthenticationMethods "publickey,password"' >> /etc/ssh/sshd_config
# ---
sudo systemctl restart ssh
# --- home pc
nano pkey.pem # paste
chmod 400 ./pkey.pem
ssh -i "pkey.pem" user@ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment