Archive for the ‘Command Line’ category

Manually Rotate Logs with logrotate

September 8th, 2010

The individual configuration files for logrotate are located in /etc/logrotate.d:

# cd /etc/logrotate.d/

Then, to manually rotate the logs for exim, simply run the following.

# logrotate exim

Note: you won’t see any output, but you will notice that the exim logs in /var/log are now rotated out.

Share

Securing SSH

July 29th, 2010

Best Security Practice
The ideal ssh daemon would only allow login via SSH keys. This setup can easily be configured within WHM >> Manage SSH Keys, where you’ll create a SSH key for you to login with. Once you’ve created your key, and verified that you can login with it, you’ll want to go to WHM >> SSH Password Authorization Tweak, which will disable PasswordAuthentication in /etc/ssh/sshd_config.

Medium-security Configuration
If you have clients on your server that require PasswordAuthentication, you can still lock down SSH pretty well.

    Open /etc/ssh/sshd_config in your favorite editor
 # vi /etc/ssh/sshd_config
    Disable direct root login

First, be sure that you have an alternate user configured in your environment that you can use to login via SSH. This user must also have privileges to “su” to root.

Then, set the “PermitRootLogin” directive to “no”.

PermitRootLogin no
    Change the port that sshd listens on
Port 221

Be sure to use a port equal to or less than 1024, as these are privileged ports that only root or a super-user can set daemons to listen on. If you were to configure sshd to listen on port 11223, and a user was able to take down sshd, they could then start their own sshd daemon in place of yours.

    State which users may login via SSH

If you want to only allow certain users to login via SSH, implement the “AllowUsers” directive:

AllowUsers bob frank

This will only allow ‘bob’ and ‘frank’ to login via SSH.

    Save and Restart SSH

Now save the file and restart the sshd service:

service sshd restart
Share

Locate command not found

July 29th, 2010

Error:

# locate filename
-bash: locate: command not found

This indicates that the “slocate” package is not installed. Install it with:

yum -y install slocate

Then update the database with:

# updatedb
Share

Yum rpmdb open failed

July 29th, 2010

Error: rpmdb open failed

This error occurs most frequently when the rpm database is corrupted. See below for instructions on how to rebuild the rpm database.

# yum update
Loaded plugins: fastestmirror
error: no dbpath has been set
error: cannot open Packages database in /%{_dbpath}
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 309, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 157, in main
base.getOptionsConfig(args)
File "/usr/share/yum-cli/cli.py", line 187, in getOptionsConfig
self.conf
File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 664, in
conf = property(fget=lambda self: self._getConfig(),
File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 239, in _getConfig
self._conf = config.readMainConfig(startupconf)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 804, in readMainConfig
yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 877, in _getsysver
idx = ts.dbMatch('provides', distroverpkg)
TypeError: rpmdb open failed

The most common fix is as follows:

# yum clean all
# rm -f /var/lib/rpm/__db*
# rpm –rebuilddb
# yum update

However, if this is a VZ container (VPS), the following may be required:

#mv /dev/urandom /dev/urandom.back
#mknod -m 644 /dev/urandom c 1 9

Share

Install chkrootkit

July 29th, 2010

How to Install chkrootkit:

# cd /usr/src
# wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
# tar -xvzf chkrootkit.tar.gz
# cd chkrootkit-*/
# make sense

After that it is ready to use and you can simply type:
# ./chkrootkit

Share

How to Increase the Serial Number For All DNS Zones

July 29th, 2010

NDCHost has made available a nice script that will increase the serial numbers for all DNS zones:

# cd /sbin
# rm -f updateserial
# wget http://www.ndchost.com/cpanel-whm/scripts/updateserial/download.php
# chown root.root updateserial
# chmod 0750 updateserial
# /sbin/updateserial -d /var/named

To activate your changes, be sure to reload rndc:
# rndc reload

Share

info [rebuildhttpdconf] User ‘username’ data set has no ‘main_domain’ key.

May 21st, 2010

Error: info [rebuildhttpdconf] User ‘username’ data set has no ‘main_domain’ key.

Solution: Check to see if there is a file called “main” for the user(s) affected users in /var/cpanel/userdata/username.

If it’s not present, verify the domain exists in httpd.conf, and run /usr/local/cpanel/bin/userdata_update to recreate the “main” file based off the apache configuration.

Share

Reverse DNS on cPanel

May 3rd, 2010

97%* of providers don’t allow their customers complete control of reverse DNS. If you’re part of that 3%*, check out this wiki article as a resource.

* Statistics made up, but accurate from what I’ve seen.

Share

info [rebuildhttpdconf] User ‘username’ data set has no ‘main_domain’ key.

May 3rd, 2010

Error:

info [rebuildhttpdconf] User 'noothna' data set has no 'main_domain' key.

Check /var/cpanel/userdata/username/main and main.cache to verify it has the necessary content. Check another domain’s main and main.cache accounts to verify what you should be seeing there.

Share

Fatal! Write Failure to /etc/valiases

May 3rd, 2010

Fatal! Write Failure: /etc/valiases/yourdomain.tld. Ignore any messages of success this can only result in failure!

First, verify that your domain exists (as a file) in /etc/valiases, and that it has “username:mail” permissions.

# touch /etc/valiases/yourdomain.tld
# chown username:mail /etc/valiases/yourdomain.tld

Share

cPanel Web Site Hosting by IntraHost