Linux/Unix

Anything unix or linux related

Server down

- Posted in Linux/Unix by

In the morning I found out, my fbin.in server is down. When I checked, I cannot see the server in my list of products.

I have reached out to the support team, and awaiting for their Germany login time to reply.

Not even sure how this happened, as my other servers are running fine. Finding it very odd.

There is one more point which comes to mind: if I had a good ISP provider at home, and port openings, this would probably be with me, but home-server is not possible, unfortunately, at least for me. :(

Update: 28.01.2026 -> So basically, I had to get a new server from them to get all up and running. Seems, and I take full responsibility for this, I only placed a cancellation order, and never realized it, or forgot all about it. Though this has nothing to do with bus factor, as even in community (take Bento's docker issue for example), the ownership remains with 1 person, the owner.

Anyways, my instances are all up and running now, and hopefully, I will not face this situation again.

Upgrade Forgejo

- Posted in Linux/Unix by

Forgejo is the best when it comes to hosting your own stuff over a git. Rest all for me have been dull, and I get the pain for setting up any sort of app/software.

Anyhow, what I love about the binaries is, forgejo for one is the simplest to setup. Here is how I do it:


systemctl stop forgejo.service && wget https://codeberg.org/forgejo/forgejo/releases/download/vX.X.X/forgejo-X.X.X-linux-amd64 && chmod +x forgejo-X.X.X-linux-amd64 && cp forgejo-X.X.X-linux-amd64 /usr/local/bin/forgejo && chmod 755 /usr/local/bin/forgejo && systemctl start forgejo.service && rm forgejo-X.X.X-linux-amd64 && systemctl status forgejo.service

Simply replace the X.X.X with the version you are installing. Example: 11.0.9 or 13.0.4 (latest ones).

So something like:

systemctl stop forgejo.service && wget https://codeberg.org/forgejo/forgejo/releases/download/v13.0.4/forgejo-13.0.4-linux-amd64 && chmod +x forgejo-13.0.4-linux-amd64 && cp forgejo-13.0.4-linux-amd64 /usr/local/bin/forgejo && chmod 755 /usr/local/bin/forgejo && systemctl start forgejo.service && rm forgejo-13.0.4-linux-amd64 && systemctl status forgejo.service

or for the LTS:

systemctl stop forgejo.service && wget https://codeberg.org/forgejo/forgejo/releases/download/v11.0.9/forgejo-11.0.9-linux-amd64 && chmod +x forgejo-11.0.9-linux-amd64 && cp forgejo-11.0.9-linux-amd64 /usr/local/bin/forgejo && chmod 755 /usr/local/bin/forgejo && systemctl start forgejo.service && rm forgejo-11.0.9-linux-amd64 && systemctl status forgejo.service

Copy Move

- Posted in Linux/Unix by

To ensure . files get moved/copied in one go.

Run - shopt -s dotglob

Then example - mv /tmp/home/source/* /home/destination/

You can put - shopt -s dotglob in your ~/.bashrc if you want it to be the default

Then run - source ~/.bashrc for it to reload

This I got from: Ubuntu Answers

CHATTR - DNS Nameserver file (immutable)

- Posted in Linux/Unix by

Check if immutable attribute is currently applied or not:

lsattr /etc/resolv.conf

Result

----i---------e------- /etc/resolv.conf

Remove it:

sudo chattr -i /etc/resolv.conf

Verify:

lsattr /etc/resolv.conf

Result

--------------e------- /etc/resolv.conf

Make changes to the resolv file for DNS nameservers:

nano /etc/resolv.conf CTRL+X (save) > Y > ENTER

Apply the attribute again:

sudo chattr +i /etc/resolv.conf

Verify:

lsattr /etc/resolv.conf

Result

----i---------e------- /etc/resolv.conf

Ubuntu Forum

CHOWN & CHMOD - R

- Posted in Linux/Unix by

CHOWN

chown -R user:mail ./* ./.[!.]*


CHMOD

-#to remove executable permissions

chmod -R 600 /path

-# to make directories transversal

chmod -R u=rwX,g=,o= /path

Above. for the user owner i'm giving capital "X", so it does apply only to directories and not files

-# all files in the current directory, recursively, including hidden files

chmod 755 -R ./* ./.[!.]*

-#all files in the current directory, not recursively, including hidden files

chmod 755 ./* ./.[!.]*

Notes: This will not change an exception filename starting with 2 dots, as example,

./..weirdfilenamehere.txt

Also, be careful not to remove the x bit, or else all your directories will not be accessible (one needs the x bit to cd into a directory).

Remember this: never use bare * but ./* instead.

To avoid problems setting permissions on directories, use find instead.

find . -type f -exec chmodVALUE{} \;


ACL (Access Control Level)

-# To apply the ACL

setfacl -Rm u::rwX,g::0,o::0 /path

-# To make the applied ACL default policy so newly created files will inherit the desired permissions.

setfacl -Rm d:u::rwX,g::0,o::0 /path

Again using capital X so it applies only to directories and not files.

CHOWN - Stackoverflow Forum || CHMOD & ACL - SuperUser Forum

Linux - Find files having 0777 permission level!

- Posted in Linux/Unix by

A 0777 permission means -rwxrwxrwx for files & drwxrwxrwx for folders. Look it up here for more details.

Again, I will not try and go on about how security matters and how the incorrect file permission makes your Linux system vulnerable.

A file with permission 0777 is open to everyone for read and write. Any user logged in to system can write to this file. Which can be harmful for your system.

In some conditions you do require 0777 permissions, like log files. However, in most cases it is best to not have this.

The easiest way to locate all files having 0777 permission is:

find /path/to/dir -perm 777

The -perm command line parameter is used with the find command to search files based on permissions. You can use any permission instead of 777 to find files with that permission details only.

For example to search all files with permission 0777 under the logged in user home directory, type:

find $HOME -perm 777

The above command will search all the files & directories with permission 777 under the specified directory.

But if you don’t want to include directories in this list. Define the type with -type in command line parameter as below.

This will search only files with permission 777 under the /var/www directory.

find /var/www -perm 777 -type f

To search for directories only, type:

find /var/www -perm 777 -type d

Linux - Change Permissions Recursively

- Posted in Linux/Unix by

I will not go long, but never, never, ever set file permissions to 0777 on production servers (or for that matter any server). This leads to WORLD writable and leads to security issues, including take-over/spamming and what not.

Always keep the file and directory permissions to minimal. Many applications frameworks request/suggest to keep permissions for all directories to 0755, and all files to 0644.

So, let us try that out and do it smartly this time.

Change Permissions Recursively

Change directory with cd command to the desired location under which you need all directories to have the permission level to 0755, and all files to 0644.

cd /home/user/public_html

Then use the first command below to chmod 0755 for all directories and sub directories. The second command will change all the files permission to 0644 (chmod 0644) under the directory tree.

find . -type d -exec chmod 0755 {} ; find . -type f -exec chmod 0644 {} ;

You can also change permission using xargs command to do this quickly.

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644

Here the directory permission 0755 is similar to “rwxr-xr-x” and the file permission 0644 is equal to “rw-r–r–“.

Change Permission for Specific files

Instead of changing permission for all files, you can also target the specific files with similar extensions. For example, if you have a PHP application on your server, & you don’t want to allow others to execute the PHP files, then use the following command to chmod 0640 all of those files with php extension:

find . -type f -name "*.php" -exec chmod 0640 {} ;

The file permission 0640 will restrict others with no permissions. This adds an extra layer of security under permissions.

[Unix/Linux] Manipulating PDF's

- Posted in Linux/Unix by

This thread is just to share couple of excellent applications, open source and for Unix/Linux systems (probably has windows package too) for arranging PDF files, and or combining, bursting PDF files.

We all know how these portable document files are, and so heavy too. Unlike PDF24, which is only for windows, this application is a great tool for people like myself, who prefer GUI over CLI (though, I admit, CLI is more intuitive then GUI), but trust me, GUI has its niche and is better eyed compared to CLI.

For the most part, PDF documents are generally designed to be read, but not altered or modified (coming from old ages). They are useful for sharing information in a consistent format, but manipulating the contents of a PDF document can be medial to difficult. Many applications which display PDFs do not provide the necessary tools for editing or rearranging the pages of these documents.

First, let's look at a desktop application for managing PDFs.

PDFArranger can generally be found in the repositories of modern versions of most distributions.

The application features a pleasantly simple interface. At the top of the window is a menu bar where we can choose to import existing documents and perform simple manipulations on documents or pages we have selected. Below this, the bulk of the window displays the document pool. Any PDF we import into PDF Arranger is divided into individual pages. These pages are displayed, in order, in the pool. If we import multiple documents, their pages will all be shown in the pool.

We can then use the mouse to drag and drop a page into a new order in the pool. We can also use the Shift and arrow keys to highlight groups of pages to manipulate. Once a page (or multiple pages) have been highlighted, we can choose an action to perform on them. We can delete pages from the pool, rotate them, or crop their edges. Then we can re-arrange them into the order we like.

Once we have re-arranged and manipulated the pages into the form we want, we can either select a range of pages to export into a new PDF, or we can export the entire pool into one new, big PDF.

PDFArranger PDF Arranger -- Manipulating a single PDF page


There are also command line tools for working with PDFs. My favorite is a tool called PDFtk. Now, to be accurate, there is a desktop version of PDFtk, but I prefer PDF Arranger's desktop interface while I like the flexibility and script-ability of the command line version of PDFtk.

The PDFtk program is run with a series of parameters. Typically we start by passing PDFtk a list of documents we want to manipulate. Then we provide it with an action command, indicating what kind of operation we are performing. Then we provide the keyword output followed by the name of the file we are going to create. This output file contains our changes.

In its simplest form, PDFtk does not need to be given any action command. We can, technically, give it an input file to work on, the keyword output, and the name of a new file to create. This effectively makes a new copy of our PDF. This can be useful either for testing purposes or to try to repair any damaged meta-data in the original document. Here is what a PDFtk command looks like when we want to just make a clean copy of the original file:

pdftk original.pdf output new-file.pdf

While PDFtk supports a lot of action commands and options, I want to focus on five. These are called:

  • cat - merge together a series of pages from one or more documents
  • shuffle - collate multiple pages, usually from multiple files
  • burst - expand one PDF document into multiple, one-page documents
  • rotate - turn pages on their sides
  • unpack_files - extract files embedded in a PDF and save them in a directory

Let's look at a few examples of these action commands being used. This first example uses the cat action command. This allows us to either insert pages of documents into one big document, or possibly remove a series of pages. Here we append one PDF to another one, making one long document:

pdftk original-one.pdf original-two.pdf cat output new-long-file.pdf

We can also specify a range of pages to collect and place in the output file. For instance, here we take the first 5 pages, and then every page from page 20 until the end of the document. All of these end up in one final PDF with the original pages 6 through 19 removed.

pdftk original-file.pdf cat 1-5 20-end output new-file.pdf

Here is one more example where we simply reverse the order of all the pages in a document, handy for when we fed pages the wrong way around into the scanner:

pdftk backward-file.pdf cat end-1 output proper-order.pdf

The shuffle command works in a similar way to cat, but it takes the first page of each specified file/range in parallel and places them in the output file. This effectively collates the original files. The next example effectively merges two documents, placing their pages together as if they were shuffled together like a deck of cards:

pdftk left-pages.pdf right-pages.pdf shuffle new-book.pdf

The next example takes one PDF file and creates a new PDF for each page included in the original. When it is done we end up with files named pg_0001.pdf, pg_0002.pdf, pg_0003.pdf, etc:

pdftk original-file.pdf burst

The rotate command is fairly straight forward. It turns a PDF's pages around, usually 90 degrees left or right. We can also tell PDFtk to rotate a page to an absolute position using the four compass directions: north, south, east, and west. For example, this command rotates every page 90 degrees to the right:

pdftk original-file.pdf rotate 1-endright output new-file.pdf

While this next example will turn all the pages in the document upside down. This is again helpful if every copy was scanned upside down and we want to correct it:

pdftk upside-down-file.pdf rotate 1-endsouth output fixed-file.pdf

Finally, the unpack_files command extracts the file elements from a PDF and places them in a directory. In this case we dump the contents of the PDF into a new directory called target-directory:

pdftk original-file.pdf unpack_files output target-directory

The PDFtk software can do more operations, including compressing files and working with passwords. However, these are probably the most commonly used operations.

enter image description here PDFtk in action (free version)


Necessary Links: 1. https://github.com/jeromerobert/pdfarranger 2. https://pdflabs.com/tools/pdftk-the-pdf-toolkit