Last active
August 21, 2024 02:09
-
-
Save fcoclavero/415e16b98233028c0ae9798bdb9541e0 to your computer and use it in GitHub Desktop.
Linux cheatsheet
This file contains hidden or 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
# Add Docker's official GPG key: | |
sudo apt-get update | |
sudo apt-get install ca-certificates curl | |
sudo install -m 0755 -d /etc/apt/keyrings | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
# Add the repository to Apt sources: | |
echo \ | |
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ | |
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get update |
This file contains hidden or 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
# 0. Prerequisite: OpenSSH server installed | |
sudo apt-get update | |
sudo apt-get install openssh-server | |
# 1. Configure SSH for SFTP | |
sudo nano /etc/ssh/sshd_config # make sure the `Subsystem sftp` line looks like `Subsystem sftp internal-sftp` | |
# 2. Create a new user group and add users to it | |
sudo groupadd sftp | |
sudo usermod -aG sftp <username> | |
# 3. Configure SFTP access to the new group in the SSH config | |
sudo nano /etc/ssh/sshd_config | |
# Add the following to the end of the file: | |
" | |
Match Group sftp | |
ChrootDirectory /home/%u | |
PermitTunnel no | |
AllowAgentForwarding no | |
AllowTcpForwarding no | |
X11Forwarding no | |
" | |
# 4. Grant permissions on home folder | |
sudo chown root:root /home/<username> | |
sudo chmod 755 /home/<username> | |
# Check the permissions | |
sudo ls -ld /home/<username> | |
# It should look like: | |
"drwxr-xr-x 3 root root 4096 Aug 19 12:00 /home/<username>" | |
# 5. Create a subdirectory for uploads, and set the appropriate ownership: | |
sudo mkdir /home/<username>/uploads | |
sudo chown <username>:sftp /home/<username>/uploads | |
# 6. Restart the SSH Service | |
sudo systemctl restart ssh | |
# 7. Test the SFTP Connection | |
sftp <username>@<server-ip> |
This file contains hidden or 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
# Open a screen session, create a new window, and start a shell in that window: | |
screen | |
# Start named session: | |
screen -S session_name | |
# Reattach screen: | |
screen -r $SCREEN_ID | |
# List running screens: | |
screen -ls | |
# Shortcuts: | |
# `Ctrl+a ?` List screen commands | |
# `Ctrl+a c` Create a new window (with shell) | |
# `Ctrl+a "` List all window | |
# `Ctrl+a 0` Switch to window 0 (by number) | |
# `Ctrl+a A` Rename the current window | |
# `Ctrl+a S` Split current region horizontally into two regions | |
# `Ctrl+a |` Split current region vertically into two regions | |
# `Ctrl+a tab` Switch the input focus to the next region | |
# `Ctrl+a` Toggle between the current and previous region | |
# `Ctrl+a Q` Close all regions but the current one | |
# `Ctrl+a X` Close the current region | |
# `Ctrl+a d` Detach screen |
This file contains hidden or 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 new user | |
sudo adduser <username> | |
# Add user to sudoers | |
sudo usermod -aG sudo <username> | |
# Check disk usage per use | |
sudo du -sh /home/* | sort -h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment