Skip to content

Posts from the ‘Linux Quick Tips’ Category

23
Jul

Check if a Service is Running Using Telnet and How to Quit Telnet Session

Telnet is not used that much anymore. To connect to a managed switch CLI this could be your only options. But then telnet has other use: you can check if a service run on a port on a remote machine.

For example to check if mysql server is running on a remote machine:

 # telnet 10.0.0.20 3306
Trying 10.0.0.20...
Connected to 10.0.0.20.
Escape character is '^]'.
J
5.6.36�-;#:<]A�w7HDZ{|{tV24mysql_native_password

To check if ssh is running on a remote machine:

 # telnet 10.0.0.20 22
Trying 10.0.0.20...
Connected to 10.0.0.20.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.2
 
Protocol mismatch.
Connection closed by foreign host.

You should get some reply from the remote machine with a text.

If you get no reply that means either that the service is not running or the service is running on other port (in case of SSH) or that the remote machine’s firewall blocks the access from outside to that service.

Now, if you want to quit telnet you will notice Ctrl + C is not working.

In order to quit telnet press Ctrl + ] to get to telnet console then type: quit

14
Jul

Find Out the Version of Your Ubuntu Linux

To find out which version is the Ubuntu Linux installed on your machine you must use the lsb_release command:

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.04
Release:	17.04
Codename:	zesty
10
Feb

Configure Networking in Ubuntu 16.04 Server

One way on some Ubuntu versions was to edit /etc/network/interfaces and add the the configuration of network interface. On Ubuntu 16.04 I’ve don the following setup:

# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

And then we create a file in /etc/network/interfaces.d called enp0s3:

# cat enp0s3
auto enp0s3
iface enp0s3 inet static
  address 10.0.0.211
  broadcast 10.0.0.255
  netmask 255.255.255.0
  post-up route add default gw 10.0.0.1
  pre-down route del default gw 10.0.0.1
 
dns-nameservers 10.0.0.1
24
Oct

Rename Multiple Files in Linux

To rename multiple files in Linux run from the command line:

for f in *.cc; do mv -- "$f" "${f%.cc}.cpp"; done

Previous command will rename all .cc files into .cpp files.

Note: It will not work recursively. To rename recursively use the following command:

find ./ -type f -exec rename 's/.mm/.cpp/' '{}' \;
25
Apr

Add an user to Ubuntu Linux from command line

If you want to add an user to your Ubuntu Linux machine here is what you need to do. Login as root (or use sudo) and then run (as root):

useradd -d /home/john -m john
passwd john
usermod -aG sudo john

If you are not root run:

sudo useradd -d /home/john -m john
sudo passwd john
sudo usermod -aG sudo john

In our example john is the user we want to add. Last command (usermod) will allow our user to run root commands via sudo.

25
Apr

Becoming root on Ubuntu Linux

If you are using Ubuntu Linux you’ve logged in as an user. If you want to become root so you won’t have to input sudo on every command you run, here’s what you need to do:

sudo su

or

sudo su -

which is probably what you really want. su – will invoke a login shell after switching the user. Just running su with no parameters will just switch the user (keeping the old shell and environment variables).

You can also run:

sudo -i

Then you get the root prompt and you will be able to run any command as root.

25
Apr

Dealing with “Bad: new password is too simple” issue on Ubuntu Linux

Let’s say you’ve booted with Live Ubuntu CD/DVD and you want to change the password of your user which is called ubuntu on Live Ubuntu CD/DVD. If you run:

passwd

you might get an error like:

You must choose a longer password

or:

Bad: new password is too simple.

You can bypass those checks by running passwd as a root with sudo:

sudo passwd

That way you will be allowed to enter short or too simple passwords which sometimes you need for testing purposes. Of course you will not use such passwords on machines connected to the internet but maybe only on test machines, maybe in virtualized environments.

24
Apr

Installing VirtualBox Guest Additions on Ubuntu Linux Guest

If you want to install VirtualBox Guest Additions on Ubuntu Linux Guest here what you need to do.

First go to VirtualBox -> Devices and click on Insert Guest Additions CD Image.

From the terminal look where the image is mounted. Usually it is under:

/mnt/username/VBOXADDITIONS_5.0.18_10667

where username is your username used to login to your machine.

Then we need to install some packages:

sudo apt-get update
sudo apt-get install build-essential linux-headers-$(uname -r)

Then we run the script from the CD image:

cd /mnt/username/VBOXADDITIONS_5.0.18_10667
sudo ./VBoxLinuxAdditions.run

You need to run this script after every kernel update.

24
Apr

Fixing: apt-get install mc is not available error on Ubuntu

So you’ve just installed Ubuntu 16.04, you’ve configured networking and it works properly but when you want to install Midnight Commander (or other package) you get an error:

apt-get install mc is not available

To fix the problem run first apt-get update command:

sudo apt-get update

Then try to install mc:

sudo apt-get install mc

Of course there could be other reasons (like your /etc/apt/sources.list file missing or containing wrong links to package repos) but on a default Ubuntu installation this could fix the problem).

24
Apr

Install VirtualBox Guest Aditions on CentOS 7 Linux Guest

If you want to be able to move your mouse cursor outside the VirtualBox CentOS Guest window without pressing a key and also automatically scale CentOS Guest window you need to install VirtualBox Guest Aditions on your CentOS Guest.

In order to do that run:

yum install dkms
yum install kernel-devel

Then add the cd from VirtualBox (Devices -> Insert Guest Aditions CD image). If you are using a window manager (like for example Mate) the iso will be mounted in /run/media where we can find the install script:

cd /run/media/root/VBOXADDITIONS_5.0.18_106667/
./VBoxLinuxAdditions.run