Last active
September 18, 2024 14:33
-
-
Save SanariSan/7fe69763459b333232e09e255de03170 to your computer and use it in GitHub Desktop.
ssh create user+key
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
# ssh to server | |
# --- | |
# add new user | |
sudo adduser user | |
# sudo cp /etc/sudoers /etc/sudoers.bak | |
# echo "user ALL=(ALL) ALL" | sudo tee -a /etc/sudoers | |
# or | |
# 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 | |
ssh-keygen -t ed25519 -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