Ubuntu Changing Hostname

Need to change your hostname? Use the following command. # sudo hostname <new-hostname> Now edit /etc/hosts and change the line starting with “127.0.1.1”. # sudo nano /etc/hosts 127.0.1.1 old-hostname <- replace this line to your new-hostname Now reboot your server, for new host name to take effect. # sudo...

Ubuntu Create New User Account

Command line for creating new user account in Ubuntu. Create a user with a standard home directory in the /home folder and specifying the default shell. # sudo useradd <username> -m -s /bin/bash Create a password for the user # sudo passwd <username> Grant administrator privilege to user # sudo adduser <username>...

Fail2ban – remove banned ip address from iptables

Your colleagues were trying to access production server via FTP. However exceeded the maximum number of failed logins, their IP address got blacklisted on iptables. How do you remove their ip address from the blacklist? Check their ip address with iptables # sudo iptables -L ... Chain fail2ban-vsftpd (1 references) target prot opt source destination DROP all -- 192.168.1.156 anywhere RETURN all -- anywhere anywhere Remove ip address from iptables # sudo iptables -D fail2ban-vsftpd -s 192.168.1.156 -j DROP Verify the iptables # sudo iptables -L ... Chain fail2ban-vsftpd (1 references) target prot opt source destination RETURN all -- anywhere...

Creating Symbolic Link (Ubuntu/Linux)

What is Symbolic Link? Creates a link to a file or directory in linux or unix operating system. Real world example Your developer are jail to their home folder for SSH connection. How to allow access to the code while enabling testing on the server? Create a symbolic link from user home directory to Apache web root directory. Syntax # ln -s <real file or directory> <virtual file or folder> Creating symbolic link for directory Assuming user denny home directory at /home/denny and apache web root document path at /var/www You will need root access to create symbolic link. # sudo mkdir /home/denny/someproject # sudo chown denny:developer /home/denny/someproject # sudo ln -s /home/denny/someproject /var/www # ls -ltr /var/www total 8 -rw-r--r-- 1 root root 177 Sep 16 22:56 index.html lrwxrwxrwx 1 root root 20 Oct 7 16:50 someproject -> /home/denny/someproject/ Creating symbolic link for file # sudo touch /home/denny/realfile # sudo chown denny:developer /home/denny/realfile # sudo ln -s /home/denny/realfile /var/www/realfile # ls -ltr /var/www total 8 -rw-r--r-- 1 root root 177 Sep 16 22:56 index.html lrwxrwxrwx 1 root root 20 Oct 7 16:50 someproject -> /home/denny/someproject/ lrwxrwxrwx 1 root root 20 Oct 7 16:54 realfile -> /home/denny/realfile To delete symbolic link Issue the rm (remove) command # rm /var/www/someproject # rm...

Add File for Additional Swap Space

If you don’t have any additional disks, you can create a file somewhere on your filesystem, and use that file for swap space. The following dd command example creates a swap file with the name “swapfile” under /root directory with a size of 1024MB (1GB). # dd if=/dev/zero of=/root/swapfile bs=1M count=1024 1024+0 records in 1024+0 records out Change the permission of the swap file, only allow root access. # chmod 600 /root/swapfile Using mkswap command make this file as a swap file. # mkswap /root/swapfile Setting up swapspace version 1, size = 1048572 KiB no label, UUID=########-####-####-####-############ Enable the newly created swapfile. # swapon /root/swapfile Using your favourite text editor, append the following line to the /etc/fstab file, to make this swap file available as a swap area even after a reboot. # nano /etc/fstab /root/swapfile swap swap defaults 0 0 Verify the newly created swap area. # swapon -s Filename Type Size Used Priority /dev/xvdb partition 524284 0 -1 /root/swapfile file 1048572 0 -2 To verify whether the system takes all the swap space mentioned in the /etc/fstab without rebooting, you can do the following, which will disable and enable all the swap partition mentioned in the /etc/fstab #swapoff -a #swapon -a #swapon -s Filename Type Size Used Priority /dev/xvdb partition 524284 0 -1 /root/swapfile file 1048572 0...