Linux Server Management Command Guide - torarnehave1/slowyouio GitHub Wiki
Here's a markdown document organized by themes for the provided Linux server commands, focusing on their functionality:
# Linux Server Command Summary
## Package Management
Commands related to updating, upgrading, and installing packages.
```bash
sudo apt install nginx
sudo apt update
sudo apt upgrade
apt list --upgradable
sudo apt install certbot python3-certbot-nginx
apt-get install nodejs -y
sudo apt-get install gnupg
sudo apt install mongodb-org
Navigation and File Management
Commands for navigating directories and managing files.
ls
cd ..
dir
cd etc
cd nginx
cd var
cd www
cd html
cd CSSFramework
cd snap
cd histories
cd opt
cd server
File Editing and Viewing
Commands to create, delete, view, and edit files.
sudo nano sites-available/default
vim default
echo >> /etc/cron.d/cronscript
cat /etc/apt/sources.list.d/mongodb-org-4.4.list
Delete a single file: rm filename
Delete multiple files: rm file1 file2 file3
Delete files interactively (with confirmation): rm -i filename(s)
Force delete without prompting, even if write-protected: rm -f filename(s)
Delete files with a specific extension: rm *.txt
Delete a directory and its contents recursively: rm -r directory
System Control
Commands for managing system services and rebooting the system.
sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl status cron
sudo reboot
sudo restart
Security and Certificates
Commands related to securing connections and managing SSL certificates.
sudo certbot --nginx
sudo certbot --expand -d slowyou.io -d www.slowyou.io
sudo nginx -t
Networking and DNS
Commands for managing DNS records and network services.
dig +noall +answer maiken.slowyou.io A
nslookup -type=A maiken.slowyou.io
Software Installation via Scripts
Commands involving the use of scripts to install and update software.
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo /opt/scripts/script.sh
Git and Version Control
Commands for cloning repositories, pulling updates, and managing local repositories.
git pull
git clone https://github.com/torarnehave1/Myfirstwebsite
git clone https://github.com/torarnehave1/site2
Node.js and NPM
Commands related to Node.js and npm, including installations and managing packages.
node -v
npm -v
npm install -g [email protected]
npm install uuid@latest
sudo npm install pm2@latest -g
PM2 Process Manager
Commands for managing applications with PM2, a process manager for Node.js applications.
pm2 start server.js --name "my-site2"
pm2 list
pm2 stop
pm2 stop my-site2
PM2 is a popular process manager for Node.js applications that provides an easy way to manage and daemonize applications. It helps you keep applications alive forever, reloads them without downtime, and facilitates common DevOps tasks.
Here’s how you can install PM2 on a Linux system:
Step 1: Install Node.js
PM2 is a Node.js application, so you need Node.js and npm (Node Package Manager) installed on your system. Here's how to install Node.js and npm using a Node Version Manager (nvm), which allows you to switch between Node versions easily.
-
Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
- This script clones the NVM repository to
~/.nvm
and adds the source line to your profile (~/.bashrc
,~/.zshrc
,~/.profile
, or~/.bash_profile
).
- This script clones the NVM repository to
-
Source your profile to add nvm to your PATH:
source ~/.bashrc
- Replace
~/.bashrc
with the appropriate file if you are using a different shell.
- Replace
-
Install Node.js:
nvm install node
- This command installs the latest version of Node.js.
-
Verify Node.js and npm installation:
node -v npm -v
- This confirms that Node.js and npm are installed correctly.
Step 2: Install PM2
Once Node.js is installed, you can install PM2 using npm.
sudo npm install pm2@latest -g
- The
-g
flag installs PM2 globally, allowing it to be run from anywhere on your system.
Step 3: Start an Application with PM2
To use PM2 to start a Node.js application, navigate to the directory where your application’s server.js
(or any other entry file) is located and run:
pm2 start server.js
Step 4: Manage Processes
Here are some basic commands to manage your Node.js applications with PM2:
- List all processes:
pm2 list
- Monitor processes:
pm2 monit
- Stop an application:
pm2 stop app_name_or_id
- Restart an application:
pm2 restart app_name_or_id
- Delete an application from PM2’s list:
pm2 delete app_name_or_id
Step 5: Configure PM2 for Startup
To ensure your apps start on boot, PM2 provides an easy setup command:
pm2 startup
- This command generates a startup script to keep your applications alive after the system reboots.
Step 6: Save Your Process List
To save the current process list for automatic respawn at reboot, use:
pm2 save
Additional Notes
- Updating PM2: To update PM2, use
npm install pm2@latest -g
and then runpm2 update
to update in-memory processes. - Logs: Check application logs with
pm2 logs
(useful for debugging).
By following these steps, you can set up PM2 to manage and monitor your Node.js applications efficiently, providing resilience and facilitating common system administration tasks.
Logging and History
Commands to view and export command histories and system logs.
history
history >> histories.txt
sudo tail -n 20 /var/log/syslog
MongoDB Installation and Configuration
Commands related to the installation and setup of MongoDB, a NoSQL database.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
This document organizes and outlines the various Linux server commands used across different functionalities, providing a clear reference for system management and operations.
This structure groups similar commands together under functional headings, making it easier to understand the purpose and use of each command within a Linux server environment.