Home | About Me
| | | | | | | | | |

Ubuntu Terminal - adding user with SSH access

Random | 26 Jul 2016
Tags: ubuntu, terminal, user, add, manage, delete, sudo, linux


In the following example I'm doing the following


# creating user
adduser [username]

# adding user to sudo (administrative privelleges)

# search for a line "root ALL=(ALL:ALL) ALL" and add a new line there
[username] ALL=(ALL:ALL) ALL

# delete a user
deluser [username]

# when deleting the user, the line added in visudo should be also deleted
# delete home directory of the user along with the account deletion
deluser --remove-home [username]
# adding user without password, with ssh access and sudo 

# 1. adding user without password
adduser --disable-password --gecos "" [username]

# 2. creating ssh user and supplying the public key
mkdir /home/[username]/.ssh
touch -f /home/[username]/.ssh/authorized_keys

echo "[public key contents]" >> /home/[username]/.ssh/authorized_keys

echo "AllowUsers [username]" >> /etc/ssh/sshd_config
sudo service ssh reload

# 3. giving sudo access
echo "[username] ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/[username]