Linux server create new user and ssh login without password

Install SSH server

$ sudo apt update
$ sudo apt install openssh-server

Check Status

$ sudo systemctl status ssh

Start SSH automatically on boot

$ sudo systemctl enable ssh

Client machine side

Generate ssh key pair
This will generate your ssh key pair

ssh-keygen

This is your public key, this key value need to be exist in the server you connect to.

more ~/.ssh/id_ras.pub

Server side

Create new user

adduser myuser
usermod -aG sudo myuser

Change to myuser account

sudo su – myuser

add client public key to authorised_keys file

mkdir ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys

(copy and paste in the value of your public key)

Disable root and password login

sudo nano /etc/ssh/sshd_config

Edit the following directive

PermitRootLogin no
PasswordAuthentication no

Reload the server

sudo systemctl reload sshd
Generate keys
ssh-keygen -t rsa

#create custom key
ssh-keygen -t ed25519 -C "Description"
#enter
/home/username/.ssh/custom_key

Copy the id_rsa.pub key to the server

ssh-copy-id username@server

#copy the custom key to server
ssh-copy-id -i ~/.ssh/skynet_key.pub username@server

or

scp ~/.ssh/id_rsa.pub username@server:~/.ssh/id_rsa_[client].pub
sudo cat id_rsa_[client].pub >> authorized_keys

restart SSH service

sudo systemctl restart ssh.service

use the custom key to connect

ssh -i ~/.ssh/custom_key username@server

or use ssh config file

nano ~/.ssh/config

Host ubuntu182
  Hostname 192.168.38.182
  User username
  Port 2222
  IdentityFile ~/.ssh/custom_key