How to add alias to your Linux

Using a Linux Operating System, there is a high level of customization, depending on your preferences or needs.

One important thing is to create alias to the most common commands in order to optimize the time you use. In mi case, I love to use “..” instead of “cd ..” or “update” to update all my Ubuntu software pending updates.

Here I put my list of aliases, it is not big but it is what I mostly use in the servers I have with Linux.

To install them, you first have to edit the file ~/.bash_alises like this:

root@rhea:~# vi ~/.bash_aliases

And insert this lines:

alias l="ls -lh --color"
alias rm="rm -i"
alias ..="cd .."
alias ...="cd ../.."
alias update='sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade'
alias clean='sudo apt-get autoclean && sudo apt-get autoremove && sudo apt-get clean'

Then you can update the alises used in your current session:

root@rhea:~# source ~/.bash_aliases
root|rhea:~$

And from that moment, you can use them.

Get IP address location info from command line

The Linux command line is a great tool. Today I’ll like to share a method to get Geographical IP information with one command, using curl and the tool of ipinfo.io.

It is as easy to use this command:

$ curl ipinfo.io/<IP Address>

Here you have an example:

You will have these parameters:

  • IP
  • City
  • Region
  • Country
  • Loc (Coordinates)
  • Org
  • Postal
  • Timezone

And that’s all. If you want more information about an IP address, you could visit the website of ipinfo.io, and you’ll get some more information and tools.

Solve issue “client intended to send too large body” in Nginx

I have faced an issue in a web server using Nginx while trying to upload a file using wordpress.

In the nginx error log I saw the error “Client intended to send too large body” in this entry:

$ tail -f /var/log/nginx/*error*.log
2020/09/01 14:31:04 [error] 884#884: *126565 client intended to send too large body: 1195619 bytes, client: 55.173.250.46, server: test.com, request: "POST /wp-json/wp/v2/media?_locale=user HTTP/2.0", host: "test.com", referrer: "https://test.com/wp-admin/post.php?post=2460&action=edit"
Continue reading Solve issue “client intended to send too large body” in Nginx

How to resolve LAN hostnames with Ubuntu

By default, Ubuntu desktop installation will provide DNS resolving configured, however in Ubuntu server installation avahi-daemon (or mdnsresponder) is needed to be installed to provide local LAN DNS resolution.

In my case, i found the error “Temporary failure in name resolution” when I tried to resolve a machine of my LAN from Ubuntu.

yvoictra@zoar:~$ ping erie.local
ping: erie.local: Temporary failure in name resolution

To solve this issue, there is no need to install a DNS server in the LAN. We can use the mDNS (Multicast Domain Name System) protocol. This protocol is used to resolve host names in a small network (LAN). The mDNS service can be contacted using UDP queries over port 5353. The mDNS protocol is published as RFC6762 and implemented by the Apple Bonjour and avahi-daemon services.

Continue reading How to resolve LAN hostnames with Ubuntu

How to activate SUDO in Ubuntu for a user

The sudo command allows users to run programs with the security privileges of another user, by default, the root user.

First if all, the user should be created in the system if it doesn’t exists yet.

On Ubuntu systems, by default members of the group sudo are granted to sudo command access.

Once the user is created, from root user, or a user with sudo access, you have to execute this command to add the user to sudo group.

sudo usermod -a -G sudo username

After this, the user will have access to sudo command.

To check if it is working, log in the session of the new user:

su - username

and execute the command:

sudo whoami

The output should be “root”, so you confirm the access has been granted successfully.

How to monitor network traffic on Ubuntu using vnStat

Monitoring network traffic or bandwitdh usage is a must in a SysAdmin tasks. There are many differents tools to manage this monitoring, but one of my favorites is vnStat. The main advantage of this tool is the simplicity of its usage.

Installation

With Ubuntu, the way to install this tool is with apt.

sudo apt-get install vnstat

First steps

Once installed, it is important to know which interfaces are going to be monitoried. For this, you can use next command

netstat -i

In my case, I have 2 interfaces (eth0, wlan0). The lo interface is the loopback interface, and this is not monitored.

yvoictra|zoar:~$ netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 0 0 0 0 0 0 0 BMU
lo 65536 58 0 0 0 58 0 0 0 LRU
wlan0 1500 12521 0 1 0 1962 0 0 0 BMRU
Continue reading How to monitor network traffic on Ubuntu using vnStat

How to set up WIFI on Ubuntu running on the Raspberry PI 4

First step is to check the status of the interfaces. For this, we will use the net-tools package.

sudo apt install net-tools

Then, we can see the interfaces status

ifconfig -a

In my case, I have this status of my interface wlan0:

ubuntu@ubuntu:~$ ifconfig -a wlan0
wlan0: flags=4098<BROADCAST,MULTICAST> mtu 1500
        ether dc:a6:32:6c:xx:xx txqueuelen 1000 (Ethernet)
        RX packets 0 bytes 0 (0.0 B)
        RX errors 0 dropped 0 overruns 0 frame 0
        TX packets 0 bytes 0 (0.0 B)
        TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

In the flags only there are 2 (BROADCAST,MULTICAST), but there is no “UP” flag.

Continue reading How to set up WIFI on Ubuntu running on the Raspberry PI 4

Create a new user in Ubuntu from terminal

In order to create a new user in a Linux Ubuntu distribution from terminal, you have to use this command.

sudo adduser username

After this, the system will ask you some parameters included the password.

[23:43:24] ubuntu|zoar:~$ sudo adduser yvoictra
Adding user yvoictra' ... Adding new groupyvoictra' (1001) …
Adding new user yvoictra' (1001) with groupyvoictra' …
Creating home directory /home/yvoictra' ... Copying files from/etc/skel' …
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for yvoictra
Enter the new value, or press ENTER for the default
Full Name []: Yvoictra
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
[23:46:40] ubuntu|zoar:~$

And it’s sucessfully created.

Customize Bash Prompt with colours in Ubuntu

There are lot of people that simply like to customize the appearence of the terminal, is my case. When you use a terminal during a lot of time, it usually helps to have a prompt more visible than the default one.

Backup

First of all, you should make a backup of the configuration file in order to fall back in case it is necessary. The file is at the user $HOME, so first step is to go the directory.

cd ~
cp -p .bashrc .bashrc-backup

Adding the new configuration in .bashrc file

Now, is the moment to edit the file .bashrc and add the new configuration to have the customized prompt.

I am used to use the vi editor to modify the configuration.

vi .bashrc

Once open the file, you should go to the end of the file. The way to do it in vi is using the key combination “Shift+G”. Once the cursor is positioned at the end, start edit mode in vi using the “o” key. Add next configuration at the end of the file.

Continue reading Customize Bash Prompt with colours in Ubuntu

How to change your language and local configuration in Ubuntu

Connect with SSH to your machine and execute next command

sudo dpkg-reconfigure locales

After this, you will see a list of languages and countries. You have to select with space bar the language and country you need. In my case, as I live in Spain, I have selected es_ES.UTF-8. It is recommended to choose UTF-8 version.

Finally, Ubuntu will ask you to select the default language to use in the operating system.

After that, you should configure the language in the keyboard with this command:

sudo dpkg-reconfigure keyboard-configuration

Now, we will configure the timezone

sudo dpkg-reconfigure tzdata

I have select the country (Europe) and the city (Madrid) where I live, so the timezone has been updated.

Finally it is recommended to reboot the system to apply the changes.

sudo reboot