Thursday, January 11, 2018

how long server has been up in linux using uptime command ?

Linux Server Uptime Command To Find Out How Long The System Has Been Running

Both Linux and Unix-like systems comes with various command to find out server uptime command. Under Linux file /proc/uptime has uptime information and file /var/run/utmp has information about who is currently logged on. However, information from /proc or utmp file is not directly readable by humans so you need to use the uptime command.
uptime - Tell how long the system has been running.

UNIX / Linux uptime command

Open a command-line terminal and then type the following commands:
Sample outputs:
 12:04:44 up 8 days, 19:42,  3 users,  load average: 1.56, 2.56, 1.96
Note: The uptime command gives a one line display of the following information.
1). The current time
2). How long the system has been running
3). How many users are currently logged on
4). The system load averages for the past 1, 5, and 15 minutes

See uptime in pretty format pass the -p option to the uptime command

#uptime -p
Sample outputs:
uptime -p
up 1 week, 1 day, 19 hours, 47 minutes

See uptime in system up since, in yyyy-mm-dd MM:HH:SS format pass the -s option to the uptime command

#uptime -s
uptime -s
2017-12-27 16:22:09

How to Disable Ctrl-Alt-Delete in Ubuntu ?

Having a physical access to the keyboard can simply use the Ctrl+Alt+Delete key combination to reboot the server without having to logged on, But we can prevent the use of this key combination on a production server for an accidental reboots.
To disable the reboot action taken by pressing the Ctrl+Alt+Delete key combination,
Comment out the following line in the file /etc/init/control-alt-delete.conf
$ sudo vi /etc/init/control-alt-delete.conf
$sudo gedit /etc/init/control-alt-delete.conf
Find line that read as follows:
exec shutdown -r now “Control-Alt-Delete pressed”
delete configuration line or comment out line by prefixing # symbol
#exec shutdown -r now "Control-Alt-Delete pressed"
Save and close the file.
But In 16.04
In the systemd world, Ctrl+Alt+Delete is handled by systemd starts this target whenever Control+Alt+Del is pressed on the console. Usually, this should be aliased (symlinked) to

Disable Ctrl+Alt+Delete using following command

$systemctl mask
$systemctl daemon-reload

Thursday, January 4, 2018

How to Find All Failed SSH login Attempts in Linux ?

Each attempt to login to SSH server is tracked and recorded into a log file by the rsyslog daemon in Linux. The most basic mechanism to list all failed SSH logins attempts in Linux is a combination of displaying and filtering the log files.
The most simple command to list all failed SSH logins is the one shown below.
#grep "Failed password" /var/log/auth.log
Sample output.
grep "Failed password" /var/log/auth.log
Sep 26 09:49:11 sshd[32138]: Failed password for ravi from port 33325 ssh2
Oct  2 23:04:25 sshd[25028]: Failed password for root from port 55800 ssh2
In order to display extra information about the failed SSH logins, issue the command as shown in the below example.
#egrep "Failed|Failure" /var/log/auth.log
In CentOS or RHEL, the failed SSH sessions are recorded in /var/log/secure file. Issue the above command against this log file to identify failed SSH logins.
#egrep "Failed|Failure" /var/log/secure
Sample output
Dec 29 16:11:01 localhost sshd[32526]: Failed password for root from port 31729 ssh2
Dec 29 16:11:04 localhost sshd[32526]: Failed password for root from port 31729 ssh2