Let's make comprehension easy ...
Everyone who uses Linux operating system today knows about Secure Server Shell. Although it is named secure server shell, is it really Secure? The answer really depends on the configuration. Let us go through the steps involved in installing and configuring SSH with focus on making the system more secure and following good practises. In general, following are the good practises:
In ubuntu operating system below is the command to install SSH service:
Once the installating is complete, the service starts listening on port 22. This can be verified by running port scan using nmap linux tool.
Now create a file /etc/issue with the legal message you want to display before login.
Then restart the ssh service to get the new configurations in effect: sudo services ssh restart
There can be a pair of keys generated and used for authentication over SSH. One key is private while the other is public. The public key is pushed to server while the private key is kept somewhere safe on the client computer. In order to generate such a key, the command is:
Then enter he passphrase and the file names. The passphrase is used to store the private file with some encryption on the local computer.
Once the files are generated, let us now push the public key to the server in which we want to login:
The above command adds the public key to the server's .ssh/authorized_keys file
Then to login, simply enter
Once you are able to login successfully, turn off the PasswordAuthentication to no in the config file described above.
Last login and last back login attempt can be checked using the following command:
While ICMP request can be used to probe if the system is active, someone can also use to do the same. Hence a right way to ensure a server is up is by installing a monitoring service that send heartbeats to some external service or system. I prefer to block all ICMP requests using IP tables and below are the commands to do so:
iptables -A OUTPUT -p icmp -o eth0 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -i eth0 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type destination-unreachable -s 0/0 -i eth0 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type time-exceeded -s 0/0 -i eth0 -j ACCEPT
iptables -A INPUT -p icmp -i eth0 -j DROP
Sometimes, we get an error although we have followed all the steps described above to add the ssh key to remote server:
One of the possible reason is that SSH keys that are generated are not added to ssh-agent, to fix this follow the below steps:
Comments: