Add docs + .sh files

This commit is contained in:
2024-08-07 06:44:52 +00:00
parent f7917ed781
commit 0786dafbf0
5 changed files with 131 additions and 36 deletions

34
create_ssh_key.md Normal file
View File

@@ -0,0 +1,34 @@
## Creating and Using SSH Keys
### Understanding SSH Keys
SSH keys provide a secure method for authenticating to remote servers. They consist of a public key and a private key. The public key is shared with the server, while the private key remains on your local machine.
### Generating an SSH Key Pair
To generate a new SSH key pair, open your terminal and run the following command:
```bash
ssh-keygen -t ed25519 -C "your_email@example.com"
```
Replace your_email@example.com with your actual email address.
You will be prompted to enter a passphrase for added security. It's recommended to use a strong passphrase. Store this passphrase as it will be one of our login methods.
The generated keys will be stored in the following files:
Private key: ~/.ssh/id_ed25519
Public key: ~/.ssh/id_ed25519.pub
### Adding Your Public Key to the Server
1. Copy the contents of the public key file:
2. On your server, log in as the user you created.
3. Create the .ssh directory: mkdir -p ~/.ssh
4. Create the authorized_key file:touch ~/.ssh/authorized_keys
5. Set permissions:
```bash
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
```

17
create_user.sh Normal file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
function create_user() {
read -p "Enter username: " username
sudo useradd -m -d /home/$username $username
sudo usermod -aG sudo $username
sudo mkdir -p /var/www/apps /var/www/static
echo "User $username created with sudo privileges"
echo "Apps directory created: /var/www/apps/"
echo "Static files directory: /var/www/static"
echo "Next step: Create SSH keys. Refer to: [link to SSH key creation guide]"
}
create_user

23
install_docker.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Install prerequisites
sudo apt-get update
sudo apt-get install -y ca-certificates curl
# Create directory for GPG key
sudo mkdir -p /etc/apt/keyrings
# Download and install Docker GPG key
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 Docker repository to sources.list
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
# Update package lists
sudo apt-get update
# Install Docker Engine, CLI, containerd, Buildx plugin, and Compose plugin
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
echo "Docker installation completed!"

51
install_nginx.sh Normal file
View File

@@ -0,0 +1,51 @@
#!/bin/bash
# Function to create the static configuration template
function create_static_config() {
cat << EOF > /etc/nginx/sites-available/static.example.conf
server {
listen 80;
server_name (YOUR_DOMAINS);
root (CONTENT_PATH);
error_page 404 /;
index index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
}
EOF
echo "Created static configuration template: /etc/nginx/sites-available/static.example.conf"
}
# Function to create the API configuration template
function create_api_config() {
cat << EOF > /etc/nginx/sites-available/api.example.conf
server {
listen 80;
server_name YOUR_API_DOMAIN;
location / {
proxy_pass http://localhost:(API_PORT)/;
}
}
EOF
echo "Created API configuration template: /etc/nginx/sites-available/api.example.conf"
}
# Function to install Nginx
function install_nginx() {
sudo apt update
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl enable nginx
}
install_nginx
create_api_config
create_static_config
sudo systemctl restart nginx
echo "To enable these configurations, create symbolic links to /etc/nginx/sites-enabled:"

View File

@@ -1,38 +1,8 @@
#!/bin/bash
# Update and install necessary packages
sudo apt update
sudo apt install -y curl gnupg lsb-release
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
# Install PM2
sudo npm install -g pm2
# Install Nginx
sudo apt install -y nginx
# Create files and directories
sudo mkdir -p /var/www/myapp
sudo touch /var/www/myapp/index.html
sudo ln -s /var/www/myapp /var/www/html/myapp
# Set up default Nginx config
cat <<EOF | sudo tee /etc/nginx/sites-available/default
server {
listen 80;
server_name myserver.com;
root /var/www/myapp;
index index.html;
location / {
try_files \$uri \$uri/ =404;
}
}
EOF
# Restart Nginx to apply changes
sudo systemctl restart nginx
echo "Installing and setting up nginx"
./install_nginx.sh
echo "Installing and setting up Docker"
./install_docker.sh
echo "New user creation"
./create_user.sh