Last active
May 26, 2020 23:47
-
-
Save thibaut-d/7b3972a54f8af19f737df5f495d0604d to your computer and use it in GitHub Desktop.
Linux add user cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect through ssh | |
ssh [email protected] | |
# Create the Linux user | |
sudo adduser username | |
# Check it | |
cat /etc/passwd | |
# Grant him sudo privileges (if needed) | |
sudo adduser username sudo | |
# Become the user | |
sudo su - username | |
whoami | |
#or in a new shell | |
sudo -u username zsh | |
whoami | |
# quit his sheel with ctrl+d | |
# Create a RSA Key for the user | |
ssh-keygen -t rsa -b 4096 -N 'passphrase' -C "[email protected]" -f ~/.ssh/id_rsa | |
eval "$(ssh-agent -s)" | |
ssh-add ~/.ssh/id_rsa | |
# Add ~/.ssh/authorized_keys | |
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | |
# Configure his user .ssh directory permissions | |
chmod 700 ~/.ssh | |
chmod 644 ~/.ssh/authorized_keys | |
chmod 644 ~/.ssh/known_hosts | |
chmod 644 ~/.ssh/config | |
chmod 600 ~/.ssh/id_rsa | |
chmod 644 ~/.ssh/id_rsa.pub | |
# Copy the files where you have access without sudo and download it | |
cp ~/.ssh/id_rsa /shared | |
cp ~/.ssh/id_rsa.pub /shared | |
scp -P xxxx [email protected]:/home/username/.ssh/id_rsa ~/ | |
scp -P xxxx [email protected]:/home/username/.ssh/id_rsa ~/ | |
# Tests SSH connection | |
# x.xx.xx.xx being the IP adress of the server | |
# xxxx being the SSH port, only usefull if changed | |
ssh [email protected] -pxxxx | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a docker group (if not done yet) | |
sudo groupadd docker | |
# Add the user to the docker group | |
sudo usermod -aG docker $USER | |
# Refresh the group | |
newgrp docker | |
# Test | |
docker run hello-world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect through ssh | |
ssh [email protected] | |
# Save configuration file | |
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_save | |
# Edit configuration file | |
sudo nano /etc/ssh/sshd_config | |
# Change content | |
Port 12345 #or whatever | |
PermitRootLogin no | |
PubkeyAuthentication yes | |
PasswordAuthentication no | |
# Restart ssh | |
sudo service ssh restart | |
# Exit | |
exit | |
# Connect | |
ssh [email protected] -p 12345 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment