Encrypt Files in Linux with Tomb

Introduction

In this tutorial, How to Encrypt Files in Linux with Tomb. It’s a simple shell script to allow you to encrypt folders and files in Linux.

  • The Tomb is a powerful encryption tool for Linux that allows users to create encrypted directories and files, providing an extra layer of security for sensitive data.
  • Tomb uses both GNU Privacy Guard to handle its encryption and dd to wipe and format its virtual partitions.

Installing Tomb in Ubuntu

sudo apt install -y tomb

How to encrypt Files in Linux with Tomb

First, you must use the dig subcommand to create a 150M Tomb file with “first-encrypt.tomb

tomb dig -s 150 first-encrypt.tomb

Next, You create a new key for the tomb file:

tomb forge -k first-encrypt.tomb.key

Second, You need to link the new key to your new tomb file as command below:

tomb lock -k first-encrypt.tomb.key first-encrypt.tomb

The final, You can open a new locked tomb with the open subcommand below:

tomb open -k first-encrypt.tomb.key first-encrypt.tomb

Create an image key to Encrypt files

Use the bury subcommand the combine my “first-encrypt.tomb.key” with the image.jpg

Now, You can open the tomb file using my new image key.

tomb open -k image.jpg first-encrypt.tomb

Close a tomb (fails if the tomb is being used by a process)

tomb close

Forcefully close all open tombs, killing any applications using them

tomb slam all

List all open tombs

tomb list

How do expand the size of my first-encrypt.tomb file from 150MB to 1GB:

tomb resize -k first-encrypt.tomb.key -s 1000 first-encrypt.tomb

Search your tomb

tomb index # The first, In order to search through your tomb files.
tomb search test # after search your want to 

Conclusion

With Tomb, you can easily encrypt sensitive files and keep them secure on your Linux system. You know How to Encrypt Files in Linux with Tomb. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Python Docker

Introduction

In this tutorial, How to run Python on Docker. Python is a programming language. Python Docker image is the latest point release. 

The Docker image version was released in March 2022.

Image 3.9 release
Debian 11 3.9.2
Ubuntu 20.04 3.9.5
RHEL 8 3.9.7
RHEL 9 3.9.10
Docker python 3.9.14

You need to install Docker on Ubuntu.

The working directory python docker:

root@devopsroles:~/dockerpython# ls -lF
total 20
-rw-r--r-- 1 root root  111 Nov 20 14:31 app.py
-rw-r--r-- 1 root root  236 Nov 20 15:00 Dockerfile
-rw-r--r-- 1 root root   20 Nov 20 14:27 requirements.txt

How to build a Docker container running a simple Python application.

Setup dockerfile python

Create a folder and create a virtual environment. This isolated the environment for the Python Docker project.

For example

mkdir dockerpython
cd dockerpython
python3 -m venv dockerpython
source dockerpython/bin/activate

Create a new file dockerfile python.

FROM python:3.9-slim-buster
ENV PYTHONUNBUFFERED=1
WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY . .
EXPOSE 5000

CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=5000"]

Save and close.

Create the Python App

Create an app.py file. For example as below

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
     return 'Hello, Docker!'

Save and close.

Create the requirements.txt file. This contains dependencies for the app to run.

For example, we add the packages for the requirements.txt file.

Flask=2.0.3
pylint

Or method 2: show all packages installed via pip use pip3 freeze and save to the requirements.txt file.

pip3 install Flask
pip3 freeze | grep Flask >> requirements.txt

we will test if the works localhost using the command below

python3 -m flask run --host=0.0.0.0 --port=5000

Open the browser with the URL http://localhost:5000

Docker Build image and container

You build a Docker image from created Dockerfile. Use the command below to build the Docker image

docker build --tag dockerpython .

Tag the image using the syntax

docker tag <imageId> <hostname>/<imagename>:<tag>

For example, Tag the image.

docker tag 8fbb6cdc5e76 huupv/dockerpython:latest

Now, the Run Docker image has the created and tagged with the command line below:

docker run --publish 5000:5000 <imagename>

Use the command below to list containers running.

docker ps

The result below:

You can now test your application using http://localhost:5000 on your browser.

Docker pushed and retrieved from Docker Hub

The container will be pushed and retrieved from the Docker Hub registry. The command simple

docker push <hub-user>/<repo-name>:<tag>.

On the website Docker Hub. Click Create Repository to give the repo a name.

Create 1 repo name and description as below:

Copy the command to your terminal, replacing tagname with version latest.

In your terminal, we run the command docker login to connect the remote repository to the local environment. Add username and password to valid login.

Run the command to push to the repository you created it.

docker push <hub-user>/<repo-name>:tagname

Confirm your image to be pushed to the Docker Hub page

In any terminal, Docker pulls the Docker image from Docker Hub.

root@devopsroles:~# docker pull huupv/dockerpython:latest

For example, use Docker Compose

version: "3.9"  
services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/app
      - logvol:/var/log
    links:
      - redis
  
 redis:
     image: redis
 volumes:
   logvol: {}

Conclusion

You know How to run Python on Docker. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Install MariaDB via the Docker container

#Introduction

In this tutorial, How to Install MariaDB via docker. MariaDB is a popular open-source database server.

You need to install Docker on Ubuntu.

Install MariaDB via Docker

Download MariaDB Docker Image.

docker search mariadb
docker pull mariadb

Get a list of installed images on Docker.

docker images

Creating a MariaDB Container

We will create a MariaDB Container such as the flags below:

  • –name my-mariadb: To set the name of the container. If nothing is specified a random if will be automatically generated.
  • –env MYSQL_ROOT_PASSWORD=password_secret: Setting root password to Mariadb.
  • –detach is to run the container in the background.
docker run --detach --name my-mariadb --env MARIADB_USER=example-user --env MARIADB_PASSWORD=example_user_password_secret --env MARIADB_ROOT_PASSWORD=password_secret mariadb:latest

Get the active docker container

docker ps

The container is running, How to access it?

docker exec -it my-mariadb mysql -uexample-user -p

Starting and Stopping MariaDB Container

restart MariaDB container

docker restart my-mariadb

stop MariaDB container

docker stop my-mariadb

start MariaDB container

docker start my-mariadb

In case we want to destroy a container,

docker rm -v my-mariadb

Conclusion

You Install MariaDB via Docker container. I hope this will be helpful. Thank you for reading the DevopsRoles page!

python data type cheatsheet

#Introduction

In this tutorial, we learn about Integers, Lists, Dictionaries, and Tuples. Python data type cheatsheet begins.

python data type cheatsheet

Integers

Integers represent whole numbers. Example

age = 30
rank = 20

Floats represent decimal numbers. For example,

temperature = 20.2

Strings represent text. For example

site = "devopsroles.com"

Lists represent arrays of values that may change during the program

members = ["HuuPV", "no name", "Jack"]
ages_values = [30, 12, 54]

Dictionaries represent pairs of keys and values:

phone_numbers = {"huupv": "+123456789", "Jack": "+99999999"}

The Keys and values of a dictionary can be extracted

Tuples

Tuples represent arrays of values that are not to be changed during the program

convert Tuples to list

 convert the list to a tuple

get a list of attributes of a data type

get a list of Python built-in functions

get the documentation of a Python data type

help(str)
help(str.replace)
help(dict.values)

Conclusion

You learn python data type cheatsheet. I hope this will be helpful. Thank you for reading the DevopsRoles page!

How to Deploy MongoDB as a Docker Container

Introduction

In this tutorial, How to Deploy MongoDB as a Docker container. MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.

In today’s world of modern application development, containerization has become a popular approach for deploying and managing applications.

Install Docker

You need to install Docker on Ubuntu.

How to Deploy MongoDB as a Docker Container

First, We will pull version MongoDB as command below:

docker pull mongo:3.4.4

To create a volume for the database and retain data. The command line creates the volume as below:

docker volume create mongo_data

We will deploy it

docker run -d -v mongo_data:/data/db --name mymongoDB --net=host mongo:3.4.4 --bind_ip 127.0.0.1 --port 27000

You need to verify the deployment as command below:

docker ps -a

The container is running, How to access it?

docker exec -it mymongoDB mongo localhost:27000

If you need to stop the MongoDB container.

docker stop ID

If you need to start the MongoDB container.

docker start ID

Conclusion

You have successfully deployed MongoDB as a Docker container. This approach offers flexibility, scalability, and portability for your MongoDB deployments. With containerization, you can easily manage your database infrastructure and ensure consistency across different environments. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Deploy Redmine Project Management using Docker

#Introduction

In this tutorial, How to Deploy Redmine Project Management using Docker Compose. Redmine is an Open Source project management you can install on your LAN or Cloud host.

You need to install Docker and Docker-Compose on Ubuntu.

Deploy Redmine Project Management

Create the Dockerfile

mkdir ~/redmine
cd ~/redmine
nano Dockerfile

paste the following content:

FROM redmine:5.0.3

RUN apt-get update

Save and close the file.

Create the docker-compose.yml file

nano docker-compose.yml

paste the following content:

version: '3.3'

services:

   postgres:

     image: postgres:10

     volumes:

       - ./storage/postgresql-data:/var/lib/postgresql/data

     environment:

       POSTGRES_PASSWORD: "POSTGRES12345"

       POSTGRES_DB: "redmine"

       PGDATA: "/var/lib/postgresql/data"

     restart: always

   redmine:

     build:

       context: .

     image: redmine:custom

     ports:

       - 80:3000

     volumes:

       - ./storage/docker_redmine-plugins:/usr/src/redmine/plugins

       - ./storage/docker_redmine-themes:/usr/src/redmine/public/themes

       - ./storage/docker_redmine-data:/usr/src/redmine/files

     environment:

       REDMINE_DB_POSTGRES: "postgres"

       REDMINE_DB_USERNAME: "postgres"

       REDMINE_DB_PASSWORD: "POSTGRES12345"

       REDMINE_DB_DATABASE: "redmine"

       REDMINE_SECRET_KEY_BASE: "…"

     restart: always

The deploy the container

docker-compose up -d

Access Redmine

Open your web browser to http://SERVER

Conclusion

You Deploy Redmine Project Management using Docker. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Manage Docker Containers with Yacht

#Introduction

In this tutorial, How to Manage Docker Containers with Yacht. The yacht is GUI to Manage your Docker containers.

You can deploy, modify and manage containers with Yacht. I will set up Yacht on the Linux system.

Manage Docker Containers with Yacht

First, You need to Installed Docker on Linux here.

Pull the Yacht docker image

I will pull the Yacht docker image from DockerHub. Log in to the server using the root account.

sudo su -

Create volume to hold all of the Yacht data on the server.

docker volume create yacht

Docker will deploy the image as a container on your system with the command below

docker run -d -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock -v yacht:/config selfhostedpro/yacht

After installing Yacht, you can access it via web UI in any browser.

http://IP-your-server:8000

Logging into Yacht

the default password and username to log into Yacht. admin@yacht.local/pass

Dashboard Yacht

View Applications

Manage volumes

Manage Network

Manage images by Yacht

Conclusion

You have Manage Docker Containers with Yacht. I hope this will be helpful. Thank you for reading the DevopsRoles page!

How to install Gitea repository in Ubuntu

Introduction

In this tutorial, How to install Gitea repository in Ubuntu.

Understanding Gitea

  • Gitea is a web-based Git repository management tool, similar to GitHub, GitLab, and Bitbucket. It is a self-hosted, open-source software that allows developers to create and manage Git repositories, as well as collaborate with others on software development projects.
  • With Gitea, you can create your own private Git repositories, manage access control and permissions for users and teams, and track issues and bugs with an integrated issue tracker. It also supports pull requests, code reviews, and continuous integration and deployment with built-in integrations for popular tools like Jenkins and Travis CI.
  • It is written in Go, and it’s lightweight and easy to set up and run.

Why Choose Gitea?

  • Lightweight: Gitea is very resource-efficient.
  • Open Source: It is free to use and modify.
  • Feature-Rich: Offers essential Git features along with additional tools like issue tracking and code review.
  • Easy to Install: The setup process is straightforward, making it accessible even for beginners.

Prerequisites

Before you begin, ensure you have the following:

  • An Ubuntu server instance with sudo privileges.
  • A basic understanding of terminal commands.

Install Gitea repository in Ubuntu

Install the necessary dependencies

sudo apt-get install wget get mariadb-server -y

After the installation, secure the database server as command below:

sudo mysql_secure_installation

Create a database and user

Log in to the database console as below:

sudo mysql -u root -p

Create the database

CREATE DATABASE gitea;
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY "your_password";
FLUSH PRIVILEGES;
exit

Install Gitea repository

Download and copy to /usr/local/bin

sudo wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/1.17.1/gitea-1.17.1-linux-amd64

Change the permissions

sudo chmod +x /usr/local/bin/gitea

Create a new system user for running Gitea:

sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git

Create the folder and change the permission

sudo mkdir -pv /var/lib/gitea/{custom,data,log}
sudo chown -Rv git:git /var/lib/gitea
sudo chmod -Rv 750 /var/lib/gitea
sudo mkdir -v /etc/gitea
sudo chown -Rv root:git /etc/gitea
sudo chmod -Rv 770 /etc/gitea

Create a systemd service file for Gitea.

Create a new systemd service file for Gitea by running the following command:

sudo nano /etc/systemd/system/gitea.service

Paste the following configuration into the service file:

[Unit]
Description=Gitea
After=syslog.target
After=network.target

[Service]
RestartSec=3s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/

ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file.

Start and enable the Gitea service by running the following commands:

sudo systemctl start gitea
sudo systemctl enable --now gitea

Access the Gitea web-based installer

Open a browser and point it to http://YOUR_SERVER:3000

Conclusion

You have to install Gitea repository in Ubuntu. I hope this will be helpful. Thank you for reading the DevopsRoles page!

Set A Memory Limit For Docker Containers

#Introduction

In this tutorial, How to Set A Memory Limit For Docker Containers. Docker container defaults to running without any resource constraints.

In production, each container will set a memory limit to prevent runaway resource consumption.

How to Set A Memory Limit For Docker Containers

You set hard and soft memory limits on individual containers.

Hard memory limits

Hard limit on virtual memory, any worker exceeding the limit will be immediately killed without waiting for the end of the current request processing.

Soft memory limits

Maximum allowed virtual memory per worker.

How to setting hard memory limits

Set by docker run command with “-m” or “–memory” flag. For example, set value 2g

$ docker run --memory=2g devopsroles-app:latest

How to setting soft memory limits

Soft memory limits are set with the “–memory-reservation” flag. For example, set the value to 512m of reserved memory. It will always stop if usage exceeds 512MB.

$ docker run --memory=512m --memory-reservation=256m devopsroles:latest

setting Swap Memory

The “--memory-swap" flag controls the amount of swap space available in conjunction with the “–memory” flag. For example, Container has access to 1000MB of memory of which 512MB is physical RAM. The remaining 488MB is swap space stored on disk.

$ docker run --memory=512m --memory-swap=1000m devopsroles:latest

How to disable Out-Of-Memory process skills.

The result in the container stopping with the error code is 137. Use “–oom-kill-disable” with your docker run command to disable this behavior.

Conclusion

You have Set A Memory Limit For Docker Containers. I hope this will your helpful. Thank you for reading the DevopsRoles page!

How to find large files Linux

Introduction

How to Find large files Linux. To find large files in Linux, you can use the find command along with the du (disk usage) command.

In this blog post, we will explore a simple yet powerful method to identify and locate large files in Linux using the command line.

Use find command line

The find command line can use to search any files inside a Linux Filesystem.

Find the command line inside your current working directory as the command below:

find . -type f

Filter with a minimum size of 10MB

find . -type f -size +10M

To search the entire filesystem to find the largest file.

sudo find / -xdev -type f -size +10M

Note: “-xdev flag” won’t scan other mounted filesystems in your Linux Server.

To scan all the mounted drives along with your primary filesystem

sudo find / -type f -size +10M

Find Large Unused Files: These have not been modified for more than 30 days and have a file size of at least 10 MB.

sudo find / -xdev -mtime +30 -type f -size +10M

Use the du command line

the du command to estimate file sizes in Linux. And how to find large files in Linux

List the files along with directory sizes recursively

du -ah

combined with the command sort command to sort the files in descending order. use the blocksize operator -B along with a unit of your choice. If you want to convert the sizes in MB, use unit M as a block size.

du -aBM | sort -nr

To find the largest 15 files in your entire filesystem

du / -aBM | sort -nr | head -n 15

Linux combines find and du command

find /path/to/directory -type f -size +100M -exec du -sh {} \; 2>/dev/null | sort -rh | head -n 10

Let’s break it down:

  • find /path/to/directory: Replace /path/to/directory with the actual directory path where you want to start the search for large files.
  • -type f: Specifies that you’re looking for regular files.
  • -size +100M: Filters files that are larger than 100 megabytes. Adjust this value as per your requirements.
  • -exec du -sh {} \;: Executes the du -sh command on each found file to display its size in a human-readable format.
  • 2>/dev/null: Redirects any error messages to /dev/null to suppress them.
  • sort -rh: Sorts the output in a reverse human-readable format to display the largest files first.
  • head -n 10: Displays only the first 10 lines of the output, which will be the largest files.

Conclusion

Effectively managing disk space is crucial for maintaining system performance and organization. With the find command in Linux, locating large files becomes a straightforward process. By following the steps outlined in this blog post, you can easily identify and manage large files, reclaiming valuable disk space on your Linux system.

You have to find large files in Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version