Skip to main content

Command Palette

Search for a command to run...

Secure Ubuntu server for non-root user using only SSH keys

Published
1 min read
Secure Ubuntu server for non-root user using only SSH keys
A

I will raise your revenues or decrease your costs using solutions based on logic and in most cases, it will involve a computer. Design - Build - Improve.


I design solutions to your business problem, build it with you and your team and finally scale the solution to fix other related problems.

I use Javascript and Python as the main languages for development but I am eager and faster to learn anything that would be put a solution on the table.

Here are the set of commands that you need to run as root on a new digital ocean droplet (assuming you have already setup root to have ssh access). This will setup mynewuser with passwordless sudo rights and the ability to ssh into the machine without a password (using only your ssh-key)

adduser --system --group mynewuser

mkdir /home/mynewuser/.ssh

chmod 0700 /home/mynewuser/.ssh/

cp -Rfv /root/.ssh /home/mynewuser/

chown -Rfv mynewuser.mynewuser /home/mynewuser/.ssh

chown -R mynewuser:mynewuser /home/mynewuser/

gpasswd -a mynewuser sudo

echo "mynewuser ALL=(ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)

service ssh restart

usermod -s /bin/bash mynewuser

Reference

More from this blog

V

Victor Abz

12 posts

Hello, I am Victor. I am a software engineer with corporate experience. Solution provider for #startups and #enterprise using Javascript (Node JS and React) | Python.