Ubuntu/Linux logout all users

 

To force logout all users from any Ubuntu/Linux server use following command:

ps aux | egrep '(tty|pts)' | awk '{print $2}' | xargs -n 1 kill -9

This command will get all PID’s of login sessions and kill them.

Advertisements

Quick way to add swap – Ubuntu

 

One of the quickest way to avoid out of memory errors is by adding some swap space. Swap is an area on hard drive where operating system can temporally store data that it can no longer hold in RAM.

Use following way to add additional swap space in Ubuntu:

First check about swap space with free command:

free -m

Lets say if we need 10GB of swap, for this first create a 10GB file with following command:

sudo fallocate -l 10G /swapfile

View details about created swapfile:

ls -hl /swapfile

Output:

-rw-r–r– 1 root root 10G May 19 06:54 /swapfile

Change permissions of swapfile:

sudo chmod 600 /swapfile

Set swap space with following command:

sudo mkswap /swapfile

Check for new swap space:

sudo swapon -s

Output:

Filename                Type        Size    Used    Priority
/swapfile                               file        10485756    2700    -2

Make swap file permanent by adding it in /etc/fstab

/swapfile none swap sw 0 0

ping ip with port

 

Ports are a concept of UDP and TCP. Ping messages are technically referred to as ICMP Echo Request and ICMP Echo Reply which are part of ICMP. ICMP, TCP, and UDP are “siblings”; they are not based on each other, but are three separate protocols that run on top of IP.

Therefore you can not ping a port. What you can do, is use a port scanner like nmap and check if ip/host and port are accessible.

$ nmap -p 80 www.google.com

Output:

Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-02 14:38 IST
Nmap scan report for http://www.google.com (74.125.200.106)
Host is up (0.085s latency).
Other addresses for http://www.google.com (not scanned): 74.125.200.147 74.125.200.104 74.125.200.103 74.125.200.105 74.125.200.99
rDNS record for 74.125.200.106: sa-in-f106.1e100.net
PORT STATE SERVICE
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 0.64 seconds

You can also use telnet onofri.org 80

Ubuntu 14.04 – Restore defaults of top bar in gnome session fallback

Due to some reason my top bar in gnome-panel got messed up and it not appearing as intended.

To fix this I tried to restore top bar in gnome-panel by using following command.

$ dconf reset -f /org/gnome/gnome-panel/
$ killall gnome-panel

After running above commands it appeared as intended.

Linux view all users crontab

 

In general we will use crontab – e or crontab -l to view crontab.

Both commands crontab -e and crontab -l will show only current users(where we logged in) crontab.

To view other user crontabs use following command:

$ crontab -u <userName> -l

To list guest user crontab use following command:

$ crontab -u guest -l

Before running above command you need to login into root.

In Ubuntu based operating systems we need to use sudo with above command.

$ sudo crontab -u guest -l

To view all users crontab user following command:

$ for i in $(grep -P ":[0-9]{4}:[0-9]{4}" /etc/passwd | cut -d: -f1)
do 
    crontab -u $i -l; 
done 

Hot Swapping And Hot Plugging

 

Host swapping describes replacing components without significant interruption to the system.

Hot plugging describes addition components that would expand system without significant interruption to the operation of the system.

Examples of this functionality’s :

  • Adding and replacing USB drives(USB Hard drive, USB Flash drive, USB DVD drive, and etc…).
  • eSATA
  • Web cams

-Sany

 

vsftp change root directory

 

You can change the root directory in vsftp as you wish..

If you enable chroot_local_user=YES, it will restrict local users to their home directories.

Some times you may want to change your root form home directory to other directory.

To change the home directory from user home directory to other directory add following lines in your  vsftpd.conf (/etc/vsftpd.conf).

anonymous_enable=YES

anon_root=/home/user/dir (here you can set the directory as you wish)

Following is my vsftpd.conf

listen=YES
anonymous_enable=YES
local_enable=NO
write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/private/vsftpd.pem
anon_root=/home/abc/mydir

-Sany