Thursday, December 29, 2016

Copy folder in linux without changing the existing permission.

 Sometimes we need to copy some folders without changing its permissions. But when we copy a folder to a new location, the new copy will have the copying person's permission. (Ex: If the copying person is 'root' then the new folder will have the permission only for root.
 One can copy the folder and then change the permission back to the original user. But this will difficult it the folder contains different permissions for different files or folders.
 So the solution for this is use "-pdR" options while copying.

> cp -pdR <file folder_name> <new_location>

Wednesday, December 7, 2016

Give root privileges for user on centos

By adding the user into 'wheel' group can give the root permission. Use the following command to add the user into wheel group. For this you should be login as root. Replace "username" with your one.

usermod -aG wheel username

Now switch to new user account from root.

> su - username

Check whether it works using a command which needs root privileges.

> sudo ls -ls /root

For the first time it will ask the user accounts password.

[sudo] password for username:

If the password is correct the command should execute with root privileges.

BUT if you receive a message like this.

username is not in the sudoers file. This incident will be reported.

That means the "wheel" group doesn't activated. To activate the group login as a root and check 'sudoers' file.

> visudo

That will open the 'sudoers' file. Go to the bottom and uncomment this line.

# %wheel        ALL=(ALL)       ALL

Now you can use root privileges.... ;)

Thursday, February 19, 2015

Block ports on Linux

To block port 80 (HTTP server), enter (or add to your iptables shell script): 

# /sbin/iptables -A INPUT -p tcp --destination-port 80 -j DROP
# /sbin/service iptables save

 Block Incomming Port 80 except for IP Address 1.2.3.4 

 # /sbin/iptables -A INPUT -p tcp -i eth1 -s ! 1.2.3.4 --dport 80 -j DROP


To block outgoing port # 25, enter:

# /sbin/iptables -A OUTPUT -p tcp --dport 25 -j DROP
# /sbin/service iptables save

You can block port # 1234 for IP address 192.168.1.2 only:

# /sbin/iptables -A OUTPUT -p tcp -d 192.168.1.2 --dport 1234 -j DROP
# /sbin/service iptables save

To unblock ports. 

 /sbin/iptables -A INPUT -p tcp --destination 12375 -j ACCEPT
 /sbin/iptables -A OUTPUT -p tcp --destination 12375 -j ACCEPT

/sbin/service iptables save

Monday, August 5, 2013

MySQL installation errors and solutions.

 libstdc++.so.5: cannot open shared object file


Some times while executing the "mysql_install_db" script we get this error.

While loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory

You can check whether this library file is there using this command.

>ls -l /usr/lib | grep -i libstdc++

In my case it returns
lrwxrwxrwx.  1 root root       19 Jul 26 17:34   libstdc++.so.6 -> libstdc++.so.6.0.17
-rwxr-xr-x.  1 root root   926280 Sep 21  2012 libstdc++.so.6.0.17

so I download libstdc++.so.5 rpm from here and install the rpm. After that i got the result like this.

lrwxrwxrwx.  1 root root       18 Aug  5 19:00 libstdc++.so.5 -> libstdc++.so.5.0.7
-rwxr-xr-x.  1 root root   763204 May  5 05:14 libstdc++.so.5.0.7
lrwxrwxrwx.  1 root root       19 Jul 26 17:34 libstdc++.so.6 -> libstdc++.so.6.0.17
-rwxr-xr-x.  1 root root   926280 Sep 21  2012 libstdc++.so.6.0.17

Then i try the "mysql_install_db" script and it works.

Getting (errno: 13) in mysqld.log file.

Ex:
/usr/local/mysql/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

Then check the "/var/lib/mysql" ownership.
> ll /var/lib/mysql
The "mysql" folder and its child's should have the mysql user ownership.

Getting (errno: 2) in mysqld.log file.

Ex:
130805 20:08:55 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
130805 20:08:55 [ERROR] Can't start server: can't create PID file: No such file or directory

Check whether there exist a folder called "mysqld" in /var/run and has correct permission. That folder ownership should be given to mysql user.


Before try a new installation you need to delete these 5 things.
1) /var/lib/mysql
2) /usr/bin/mysql3) /var/run/mysqld
4) /usr/local/mysql    - Symbolic link
5) /usr/local/mysql-x.x.x-m2-linux-x86_64-icc-glibc23   - The extracted folder.


Log path : /var/log/mysqld.log

Thursday, June 6, 2013

Simple tool to get diff and merge text files.

I found a simple GUI tool to diff and merge text files called Meld. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.

http://meldmerge.org/