Add key authentication and disable password in Ubuntu

(1) SSH as root user

(2) Create new user and set a passsord

$ useradd -m -s /bin/bash ubuntu
$ passwd ubuntu

(3) Add new user to sudoer group

usermod -aG sudo ubuntu

(4) Exit SSH.

(5) Run on your machine. Assuming your already have a pair of priv/pub key created.

ssh-copy-id -i $HOME/.ssh/id_rsa.pub ubuntu@ip.address.of.server

(6) Edit SSH config

sudo pico /etc/ssh/sshd_config

PasswordAuthentication no
ChallengeResponseAuthentication no

(7) Restart SSH

sudo systemctl restart ssh

(8) Edit sudoer config

sudo pico -w /etc/sudoers

ubuntu  ALL=(ALL:ALL) NOPASSWD:ALL
%sudo ALL=(ALL:ALL) NOPASSWD:ALL

AI Summary
Chrome On-device AI 2024-12-06 18:08:09

Share Article