Skip to content

Setup new user on new server

Allan Roger Reid edited this page Dec 4, 2024 · 5 revisions

Not require password to user sudo

sudo visudo

Modify content to:

#### Allow members of group sudo to execute any command
#%sudo  ALL=(ALL:ALL) ALL
%sudo   ALL=(ALL) NOPASSWD: ALL

Test

sudo -v

Add user with home

sudo userdel eco
sudo useradd -m eco

Add user to sudoers group

sudo usermod -a -G sudo eco

sudo mkdir /home/eco/.ssh
sudo vi /home/eco/.ssh/authorized_keys

Add user public key

Grant user access to all files

sudo chown -R eco:eco /home/eco

Validate no password to ssh

vi /etc/ssh/sshd_config
UsePAM no
PasswordAuthentication no

Set port to non 22

vi /etc/ssh/sshd_config
Port 4492

Restart ssh

sudo systemctl restart sshd

Grant user default shell

sudo usermod --shell /bin/bash eco

Validate

ssh eco@1.2.3.4 -o ServerAliveInterval=5 -o "ServerAliveCountMax 100000" -p 4492 -o PubkeyAuthentication=no

May need to unlock user

sudo usermod -p 123 eco
sudo usermod --unlock eco
sudo usermod -p '' eco
Clone this wiki locally