Thursday, June 30, 2016

How to CHMOD all files to 644 and all Directories to 755 via SSH

Often we find ourselves needing to bulk change all file permissions or all directory permission for an entire site or directory.
To do this with your individual ftp client is time consuming and some of the ftp software clients try to recursively change everything to the same file permission, including directories. Yes, I am talking to you WinSCP.
To separate these out you just need to log into your server or hosting account via SSH, navigate to the directory you want to start the change in and type:
find . -type d -print0 | xargs -0 chmod 0755 # For directories
or
find . -type f -print0 | xargs -0 chmod 0644 # For files
This will recursively find and apply the CHMOD accordingly for the file types. F = Files & D = Directories respectively.
If you need to change ownership of files, it is just as easy to do.
From the directory you want to start the command from you type:
chown -R username:usergroup *
This will recursively change file and directory ownership for all files and directories starting where you typed this command.
If you merely want to change ownership on a directory – you specify that as:
chown -R username:usergroup directory
or
chown -R username:usergroup directory/sub-directory/yet-another-sub-directory
That’s it – it is easy. If you need to hire some help for this – just contact us today.

Wednesday, June 29, 2016

How to open Exim port 26 on cPanel via SSH

It's no secret that ISP’s will sometimes limit traffic on the common SMTP ports (25 & 587). The result is that clients will constantly contact you because they are unable to send mail. The fix is normally to switch to the alternate port i.e. from port 25 to 587 and vice-versa. This however is only a temporary fix and the client will soon contact you (slightly more frustrated) again with the same problem.
Luckily, cPanel makes it easy to add additional ports for Exim to listen on. By opening for example port 26 on the server and asking your client to use that port instead, your "outgoing mail issue" calls will soon be a thing of the past.
In WHM, it is as simple as logging in, navigating to Service Manager and enabling the “Exim Mail Server (on another port)” option. But what if you have multiple servers? If that is the case, it is easier to do this via the command line (SSH) since you can create a script  to open the port throughout your entire cPanel cluster.
This is how you open port 26 via SSH on a cPanel server:

Step 1

Edit your exim.conf file
vi /etc/exim.conf
Find the following line. Note that the port numbers may not be in this order.
daemon_smtp_ports = 587 : 25 : 465
Now add port 26 as follows
daemon_smtp_ports = 587 : 25 : 465 : 26
Once changed, save and exit the file.

Step 2

Before you can rebuild the exim config, you need to add this entry to exim.conf.local as well, otherwise cPanel will simply override this entry when you rebuild the config.
vi /etc/exim.conf.local
Add the line to the file under the @CONFIG@ section
daemon_smtp_ports = 587 : 25 : 465 : 26
Save and exit the file

Step 3

Rebuild exim config and restart the exim service
/usr/local/cpanel/scripts/buildeximconf
service exim restart

Step 4

Open port 26 on your server firewall. This will mostly be CSF on cPanel servers.
vi /etc/csf/csf.conf
Find the “Allow incoming TCP ports” section and add port 26 as per the example below.
# Allow incoming TCP ports
TCP_IN = "20,21,25,26,53,80,110,143
Save the config file and restart CSF
csf –r
That’s it, Exim will now listen on port 26. To ensure that the port is open, you can telnet from another server to port 26 on the server where you opened the port as follows.
telnet server_ip 26
You should see something like this.
Trying server_ip...
Connected to server_ip.
Escape character is '^]'.
220-server_ip ESMTP Exim 4.87 #1 Mon, 06 Jun 2016 08:57:49 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
Although the method in this tutorial will take much longer on a single server as supposed to doing it via WHM, it will be MUCH faster if you have to do it on 100 servers via a simple bash script.
Enjoy your reduced client contact!

Wednesday, June 1, 2016

How to Fix Permissions on Files and Directories by SSH

Sometimes plugins or other features can mess up the permissions for a file or directory(folder) on your site and make it impossible for you to access something or upload something. The easiest way to fix this is with SSH access. If you do not have SSH access, contact your host and see if they allow it and can enable it for you.

To get SSH access enabled on BlueHost, see: http://helpdesk.bluehost.com/index.php/kb/article/000180

You can use the following two lines to reset your permissions. Note that the default directory permissions are 755 and the default file permissions are 644, so that is what I will show here, however, if your webhost says you need other permissions for something, then you can change the numbers. Beware of 777 permissions though, as they are a security threat! If you are told to use 777, first try it with 755 and 644, if that doesn’t work, then carefully add 777 permissions only where you need it.

Here are the SSH commands to fix your permissions on a mass level:
find ~/public_html -type d -exec chmod 755 {} \;
find ~/public_html -type f -exec chmod 644 {} \;
Basically, the format is to find, or look, in the path of ~(which means home) and then in public_html. (If you want to look in a different directory, you can change this. e.g. ~/public_html/myblog) And then it looks for the document type, be it directory (d) or file (f), and executes the chmod(change mode) command to change the permissions on all results.

Be very careful with these commands!
If you accidentally break something, it can be difficult to fix. For example, if you have cgi or perl files, they will need 755 permissions instead of 644 in order to operate properly. If you have questions in regards to this, you might want to ask first.
Be Sociable, Share!