Tuesday, 30 June 2015

How to enable root login ubuntu-15.04-server

                
The root user in Ubuntu is disabled by default because his password is not set. But if you'd like to use root user by some reason, enable it like follows.

Set root password.

root@amir:~$ sudo passwd root
Enter new UNIX password:                    # set root password
Retype new UNIX password:                # confirm
passwd: password updated successfully

root@amir:~$ su -
Password:                           # root password
root@amir:~                       ## just switched             

If you enable root, limit users to switch to root.

root@amir:~# vi /etc/pam.d/su
# line 15: uncomment and add a group that can switch to root
auth   required   pam_wheel.so   group=adm

root@amir:~# usermod -G adm root

End...

Monday, 29 June 2015

Basic Linux iptables configuration

#iptables –F
#service iptables save
#service iptables restart
#chkconfig iptables on
DDOS or similar attack prevent
#iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
syn-flood attack prevent
#iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

XMAS attack prevent
#iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP

localhost interface:
#iptables -I INPUT 1 -i lo -p all -j ACCEPT

Web server traffic:
#iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
#iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

SMTP servers:
#iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
#iptables -A INPUT -p tcp -m tcp --dport 465 -j ACCEPT

Read email
#iptables -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT
#iptables -A INPUT -p tcp -m tcp --dport 995 -j ACCEPT

MAP mail protocol:
#iptables -A INPUT -p tcp -m tcp --dport 143 -j ACCEPT
#iptables -A INPUT -p tcp -m tcp --dport 993 -j ACCEPT

Limiting SSH access
#iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#iptables -A INPUT -p tcp -s YOUR_IP_ADDRESS -m tcp --dport 22 -j ACCEPT


## delete or comment out port 22 line ##
## -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
## open port 2022
#iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2022 -j ACCEPT

Sunday, 28 June 2015

How to change all file permissions to 644 and all folder permissions to 755


How to change all file permissions to 644 and all folder permissions to 755 recursively using chmod in the following two situation:

If they had 777 permissions

find . -type d -perm 777 -exec chmod 755 {} \; (for changing the directory permission)

find . -type f -perm 777 -exec chmod 644 {} \; (for changing the file permission)

If they did not have 777 permissions, we easily remove the -perm 777 part.

look like that

find . -type d -exec chmod 755 {} \; (for changing the directory permission)

find . -type f -exec chmod 644 {} \; (for changing the file permission)


Saturday, 27 June 2015

How to reset root password RHEL, CentOS, Fedora

Here are some simple steps to change back the password by entering into single user mode of your machine provided you do not forgotten your grub password if you have set it


  1. Reboot your machine
  2. Press ‘Esc‘ key once grub starts loading
  3. Select your kernel press ‘e‘ on one of the kernel to edit the kernel parameter
  4. Press ‘e‘ on the line that starts with ‘kernel /vmlinuz…‘
  5. Append ”single” or “1” at the end of the line
  6. Press ‘Enter‘
  7. Press ‘b‘ to boot from the appended kernel
  8. You are now in the single user mode of your linux machine once you get to the shell. You can now change the password of your account using command passwd
  9. Reboot back your machine normally
  10. You can now log in to your machine using your new password

How to configure NFS RHEL, CENTOS, FEDORA


In this example, the client is 10.10.0.3 and the server is 10.10.0.1. The folder to be shared is
/home/sharing, and to be mounted to /mnt on the client
On the server
1: make   this  diretory :
[root@amir ~]# mkdir /home/sharing
2:Edit /etc/exports, insert the client computer  ip
 vi /etc/exports
and  add  this line:
/home/sharing 10.10.0.3/255.255.255.255(rw,sync)
 save  and  exit
3:  Edit /etc/hosts.allow
vi  /etc/hosts.allow
add  :  portmap: 10.10.0.0/255.255.255.0
save  and  exit.
 4:  start nfsand  portmap :
[root@amir ~]#  /etc/init.d /nfs start
[root@amir ~]#  /etc/init.d /portmap start
On the client
 start
/etc/init.d/portmap start
Mount the nfs folder
mount 10.10.0.1:/home/sharing /mnt
 Check /var/log/messages for any error that might occur
tailf /var/log/messages
Use mount to check if the folder is mounted properly
the  output  should  be  like :
10.10.0.1:/home/sharing on /mnt type nfs (rw,addr=10.10.0.1)
Edit /etc/fstab to mount the shared folder on boot  :
vi /etc/fstab
add
10.10.0.1:/home/sharing mnt nfs rw,hard,intr 0 0
 save  and  exit .

Friday, 26 June 2015

Essential Linux Find command example




1. Find Files Using Name in Current Directory
Find all the files whose name is tecmint.txt in a current working directory.
# find . -name tecmint.txt

./tecmint.txt
 
2. Find Files Under Home Directory
Find all the files under /home directory with name tecmint.txt.
# find /home -name tecmint.txt

/home/tecmint.txt

3. Find Files Using Name and Ignoring Case
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
# find /home -iname tecmint.txt

./tecmint.txt
./Tecmint.txt

4. Find Directories Using Name
Find all directories whose name is Tecmint in / directory.
# find / -type d -name Tecmint

/Tecmint

5. Find PHP Files Using Name
Find all php files whose name is tecmint.php in a current working directory.
# find . -type f -name tecmint.php

./tecmint.php

6. Find all PHP Files in Directory
Find all php files in a directory.
# find . -type f -name "*.php"

./tecmint.php
./login.php
./index.php

7. Find Files With 777 Permissions
Find all the files whose permissions are 777.
# find . -type f -perm 0777 -print

8. Find Files Without 777 Permissions
Find all the files without permission 777.
# find / -type f ! -perm 777

9. Find SGID Files with 644 Permissions
Find all the SGID bit files whose permissions set to 644.
# find / -perm 2644

10. Find Sticky Bit Files with 551 Permissions
Find all the Sticky Bit set files whose permission are 551.
# find / -perm 1551

11. Find SUID Files
Find all SUID set files.
# find / -perm /u=s

12. Find SGID Files
Find all SGID set files.
# find / -perm /g+s

13. Find Read Only Files
Find all Read Only files.
# find / -perm /u=r

14. Find Executable Files
Find all Executable files.
# find / -perm /a=x

15. Find Files with 777 Permissions and Chmod to 644
Find all 777 permission files and use chmod command to set permissions to 644.
# find / -type f -perm 0777 -print -exec chmod 644 {} \;

16. Find Directories with 777 Permissions and Chmod to 755
Find all 777 permission directories and use chmod command to set permissions to 755.
# find / -type d -perm 777 -print -exec chmod 755 {} \;

17. Find and remove single File
To find a single file called tecmint.txt and remove it.
# find . -type f -name "tecmint.txt" -exec rm -f {} \;

18. Find and remove Multiple File
To find and remove multiple files such as .mp3 or .txt, then use.
# find . -type f -name "*.txt" -exec rm -f {} \;

OR

# find . -type f -name "*.mp3" -exec rm -f {} \;

19. Find all Empty Files
To file all empty files under certain path.
# find /tmp -type f -empty

20. Find all Empty Directories
To file all empty directories under certain path.
# find /tmp -type d -empty

21. File all Hidden Files
To find all hidden files, use below command.
# find /tmp -type f -name ".*"

22. Find Single File Based on User
To find all or single file called tecmint.txt under / root directory of owner root.
# find / -user root -name tecmint.txt

23. Find all Files Based on User
To find all files that belongs to user Tecmint under /home directory.
# find /home -user tecmint

24. Find all Files Based on Group
To find all files that belongs to group Developer under /home directory.
# find /home -group developer

25. Find Particular Files of User
To find all .txt files of user Tecmint under /home directory.
# find /home -user tecmint -iname "*.txt"

26. Find Last 50 Days Modified Files
To find all the files which are modified 50 days back.
# find / -mtime 50

27. Find Last 50 Days Accessed Files
To find all the files which are accessed 50 days back.
# find / -atime 50

28. Find Last 50-100 Days Modified Files
To find all the files which are modified more than 50 days back and less than 100 days.
# find / -mtime +50 –mtime -100

29. Find Changed Files in Last 1 Hour
To find all the files which are changed in last 1 hour.
# find / -cmin -60

30. Find Modified Files in Last 1 Hour
To find all the files which are modified in last 1 hour.
# find / -mmin -60

31. Find Accessed Files in Last 1 Hour
To find all the files which are accessed in last 1 hour.
# find / -amin -60

32. Find 50MB Files
To find all 50MB files, use.
# find / -size 50M

33. Find Size between 50MB – 100MB
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M

34. Find and Delete 100MB Files
To find all 100MB files and delete them using one single command.
# find / -size +100M -exec rm -rf {} \;

35. Find Specific Files and Delete
Find all .mp3 files with more than 10MB and delete them using one single command.
# find / -type f -name *.mp3 -size +10M -exec rm {} \;