This article is particularly for you new Linux admins,
1.) When you have doubt in server check your logs. Everything is logged inside of Linux,the first thing you always need to do is checking your logs. In most systems, this is found in /var/log/, /var/log/messages, /var/log/syslog logs all the system messages and is where you will find most common error messages.
2.) You can always use the Tail command to view the last ten to twenty lines of a file. You can use the -f flag, or tail -f /var/log/syslog to watch the most recent lines append to the log file. This is a great tool to use while watching for error logs. You can also use the Head command to view the first ten lines of a specified file.
3.) Monitor your server resources. Depending on your disk and partition size, sometimes you can run out of space or your log files can take most size of your root partition. You can monitor the size of the partitions by using the df command. Two flags to know when starting are the -h and -m flag. The -h flag puts information in human readable form such as 5g. The -m flag puts information in megabyte form and displays only in megabytes.
Eg- df –Th
4.) Never Use Root user To Login on to the server. The most common hacks are done by port scanners and random password generators trying to break into your system with root as the username. The first thing you should do on your system is disable root login. You do this by going into /etc/ssh and edit sshd_config. Change this line PermitRootLogin yes to PermitRootLogin no.
PermitRootLogin yes -> change this to no like -> PermitRootLogin no
Finally restart using /etc/init.d/ssh restart (or) service ssh restrt
5.) Surely you must know about chown and chmod command.if you are going to be hosting any websites. Permissions security and file ownership are very important. Having the wrong permissions can lead a way to hack.
6.) Use SFTP instead of FTP. SFTP encrypts passwords through the tunnel where as port 21 ftp allows password information to be sent via clear text. Hackers could listen into and grab your passwords when using port 21.
7.) ls -al – LS lists the directory contents. The -a flag tells the ls command to list all files, even those that begin with a . (dot). The -l flag tells LS to list the contents and also display the date files were modified. This command should just be the basic ls -al command when you want to list directory contents.
8.) Top – top command will display your highest usage processes on your system. If your processor is running high, this will help you find the process and fix the problem.
9.) Use grep command to search files for a specific word or expression. Grep is extensive…very extensive. This is why it is one of the best tools to search files. For example, grep -r bin.sh /etc/* will recursively search the /etc/ directory and all the directors under it that have the word bin.sh.
10.) Redirect the results of a grep search into a new file. This is easy to do. We can take the search results from our command above and write them to a file instead of reading them in the shell. Just type grep -r bin.sh /etc/* > text.txt.