Enable/Disable ssh access to root

Its always better to disable ssh access to root user which will protect the server from any attacks. Its kind of additional security layer on top of firewall.

There are 2 ways to disable SSH access to root.

With DenyUsers:

In /etc/ssh/sshd_config file search for line DenyUsers, if it exists edit it as follows else add following line:

DenyUsers root

If you want to disable ssh login for multiple users on the server add as following:

DenyUsers root user1 user2 user3

After updating sshd_config add restart sshd service with following command:

$ service sshd restart

Now try to ssh to root, it should not allow login even though you entered right password.

With PermitRootLogin:

PermitRootLogin will support 2 options “yes” and “no”.

Option yes will allow ssh to root and option no wont allow ssh to root.

To allow ssh to root add following line in /etc/ssh/sshd_config file and restart sshd service:

PermitRootLogin yes

To disable ssh to root add following line in /etc/ssh/sshd_config file and restart sshd service:

PermitRootLogin no

-Sany

Reduce amount reserved free disk space with tune2fs

In Ubuntu/Debian by default while creating ext2/ext3/ext4 file system 5% of disk space is reserved for super user across each partition.

Except for root partition 5% reserved space is not required for other partitions. So we reuse that reserved space.

We can reuse this reserved space with tune2fs command.

First get file system device path for which you want to reduce reserved space. Use df -h command to get the details:

$ df -h

Output:

Filesystem   Size   Used Avail Use% Mounted on
/dev/sda5      28G   4.7G 22G   18%       /
udev             2.8G  4.0K  2.8G   1%        /dev
tmpfs            1.2G  880K  1.2G  1%        /run
none             5.0M   0       5.0M   0%        /run/lock
none             2.9G  2.2M   2.9G  1%        /run/shm
/dev/sda7     311G 166G  131G 56%   /home

To make only 2% space as reserved on /home use following command:

$ sudo tune2fs -m 2 /dev/sda7

In above command /dev/sda7 my file system device path for /home

Now check your space details with df -h and observe the size of /home partition it should be increased.

-Sany

Linux record terminal session and replay it

 

We can record and reply a terminal/konsole session with script command and reply it with scriptreply command.

Here is the example to record the session:

$ script -t 2> timing.txt -a session.txt

Output:

Script started, file is session.txt

Now you can start typing some commands.

$ echo "Hello world"
$ date

To stop recording run exit command.

$ exit

In above session we ran echo, date commands, and stored output in timings.txt and session.txt

To replay recorded session use scriptreplay as shown below:

$ scriptreplay timing.txt session.txt

It will print/replay whole session that we recorded.

-Sany