Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Sunday, January 11, 2015

How to reboot cpanel/whm in ssh

to restart the machine via ssh you type 

/etc/init.d/cpanel restart

That’s it…!!

See more at: http://datlinux.blogspot.com.es/
 Enjoy!!!

Friday, May 2, 2014

Basic SSH

If you have an account on a cPanel server with shell access or your own VPS or Dedicated server running Linux then SSH is a powerful tool to have in your skill set.

SSH (aka Secure Shell) is a way of logging into your server from a remote computer such as your home desktop or laptop. The remote connection utilizes encryption on both the server’s end and your end to keep the entire session secure.

The most common type of connection that our support department uses is to SSH into a server as the root user. Logging in as root allows you to make systemwide changes, restart important services, and perform many other tasks that only the root user is allowed to do (by default).

If you are going to initiate your remote connection from a Linux or Mac OS X computer you can start using SSH by opening up the Terminal application. Linux users should know how to find the terminal, and Mac OS X users need only open their Applications folder and then the Utilities folder to find Terminal.app. Unfortunately SSH is not built-in to Windows, so you will need to download an application like PuTTY.

Once your terminal is open you can start your SSH session as root using the following command:


ssh root@host.servername.com

This commands tells your computer “I want to open a new SSH session to the server called host.servername.com, and I want to log in as the user root.”

If this is your first time connecting to the server using this hostname your SSH client will ask if you are sure you want to connect to a new, previously unknown host. Say “yes” and you will be prompted for the root account’s password (or simply, root password). After you have typed in the password and it is accepted you will be logged in to the server as the root user.

Before you continue, it is important to note that logging in to a server as root is a powerful but also potentially DANGEROUS system administration tool. The root user is allowed to change/delete practically everything in a server without any type of warning or confirmation of changes being made. Always backup your files before you modify them using a simple backup command:


root@host [~]# cp file file.bak

For new shell users, the above command breaks down like so:

root@host [~]#

The prompt. Shows you your username (root) and the name of the server you are logged into (@host). For example: If you were logged into a server called webstuff1 and your username was bill, your prompt might display bill@webstuff1.
       
The [~]# indicates the directory you are currently looking at/working in

cp
The copy command. Tells the server to copy the file to a new file with a different name, or the same name but in a different location (path).

file
The file that you want to backup.

 file.bakThe new copy of the file that will be created. You can also specify a new location like /home/username/file.bak .
   
To review, the above command creates a copy of “file” in the same location as the original and calls it “file.bak”.

Friday, March 28, 2014

Cpanel log locations

Apache:
/usr/local/apache/logs/access_log
/usr/local/apache/logs/error_log

MySQL:
/var/lib/mysql/hostname.err

cPanel Installation Logs:
/var/log/cpanel-install-thread0.log

Apache domlogs:
/usr/local/apache/domlogs/example.com

cPanel Access Log:
/usr/local/cpanel/logs/access_log

cPanel Error Log:
/usr/local/cpanel/logs/error_log

ModSecurity:
/usr/local/apache/logs/modsec_audit.log
/usr/local/apache/logs/modsec_debug_log

Cron Logs:
var/log/cron

Apache SUEXEC Logs:
/usr/local/apache/logs/suexec_log

Exim:
/var/log/exim_mainlog
/var/log/exim_paniclog
/var/log/exim_rejectlog

BIND (named) Log:
/var/log/messages

Courier or Dovecot IMAP:
/var/log/maillog

Tomcat Logs:
/usr/local/jakarta/tomcat/logs/catalina.err
/usr/local/jakarta/tomcat/logs/catalina.out

cPanel Error Log:
/usr/local/cpanel/logs/error_log

cPanel License Log:
/usr/local/cpanel/logs/license_log

cPHulkd:
/usr/local/cpanel/logs/cphulkd.log

Stats Execution Logs:
/usr/local/cpanel/logs/stats_log

cPanel Backup Logs:
/usr/local/cpanel/logs/cpbackup/*.log

ChkServd (cPanel Monitoring Daemon) Logs:
/var/log/chkservd.log

SSH Logs:
/var/log/secure

Pure-FTP:
/var/log/messages
/var/log/xferlog (symlinked to /usr/local/apache/domlogs/ftpxferlog)

Enable Iptables Modules for a VPS

Below was the error while trying to install CSF in one of the OpenVz containers:

    ----------------------------------error--------------------------------
    [root@abc ~]# perl /etc/csf/csftest.pl
    Testing ip_tables/iptable_filter...OK
    Testing ipt_LOG...FAILED [ 4294967295] - Required for csf to function
    Testing ipt_multiport/xt_multiport...FAILED [FATAL Error: iptables: Unknown error 4294967295] - Required for csf to function
    Testing ipt_REJECT...OK
    Testing ipt_state/xt_state...FAILED [FATAL Error: iptables: Unknown error 4294967295] - Required for csf to function
    Testing ipt_limit/xt_limit...FAILED [FATAL Error: iptables: Unknown error 4294967295] - Required for csf to function
    Testing ipt_recent...FAILED [Error: iptables: Unknown error 4294967295] - Required for PORTFLOOD and PORTKNOCKING features
    Testing xt_connlimit...FAILED [Error: iptables: Unknown error 4294967295] - Required for CONNLIMIT feature
    Testing ipt_owner/xt_owner...FAILED [Error: iptables: Unknown error 4294967295] - Required for SMTP_BLOCK and UID/GID blocking features
    Testing iptable_nat/ipt_REDIRECT...FAILED [Error: iptables v1.3.5: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)] - Required for MESSENGER feature
    Testing iptable_nat/ipt_DNAT...FAILED [Error: iptables v1.3.5: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)] - Required for csf.redirect feature
    ---------------------------------------------------------------



Enable Iptables Modules for a VPS:-




1 . Before enabling the modules to a VPS , make sure that its enabled in the root node of the VPS. You can check it using the command :

lsmod | grep -i module_name



2. If its not enabled, then it can enable by using the modprobe command :-



    modprobe iptables_module

    modprobe ipt_helper

    modprobe ipt_REDIRECT

    modprobe ipt_TCPMSS

    modprobe ipt_LOG

    modprobe ipt_TOS

    modprobe iptable_nat

    modprobe ipt_length

    modprobe ipt_tcpmss

    modprobe iptable_mangle

    modprobe ipt_tos

    modprobe iptable_filter

    modprobe ipt_helper

    modprobe ipt_tos

    modprobe ipt_ttl

    modprobe ipt_SAME

    modprobe ipt_REJECT

    modprobe ipt_helper

    modprobe ipt_owner

    modprobe ip_tables

    modprobe ipt_MASQUERADE

    modprobe ipt_multiport/xt_multiport

    modprobe ipt_state/xt_state

    modprobe ipt_limit/xt_limit

    modprobe ipt_recent

    modprobe xt_connlimit

    modprobe ipt_owner/xt_owner

    modprobe iptable_nat/ipt_DNAT

    modprobe iptable_nat/ipt_REDIRECT



3. Stop the container which one you want to enable the module :

    # vzctl stop 101



4 . Executing the following command:-



a) By Command:
Execute following command to enable all the modules for the VPS


    # vzctl set 101 --iptables ipt_REJECT --iptables ipt_tos --iptables ipt_TOS --iptables ipt_LOG --iptables ip_conntrack --iptables ipt_limit --iptables ipt_multiport --iptables iptable_filter --iptables iptable_mangle --iptables ipt_TCPMSS --iptables ipt_tcpmss --iptables ipt_ttl --iptables ipt_length --iptables ipt_state --iptables iptable_nat --iptables ip_nat_ftp --save

or



b) Adding Rules manually:

Open the VPS configuration file which exists at /etc/vz/conf/veid.conf and paste following in the last line of the file.

    
    IPTABLES="iptable_filter iptable_mangle ipt_limit ipt_multiport ipt_tos ipt_TOS ipt_REJECT ipt_TCPMSS ipt_tcpmss ipt_ttl ipt_LOG ipt_length ip_conntrack ip_conntrack_ftp ip_conntrack_irc ipt_conntrack ipt_state ipt_helper iptable_nat ip_nat_ftp ip_nat_irc"



5. Restart the container.

    # vzctl restart 101

Sunday, March 9, 2014

How to Clear cPanel/WHM Brute Force Log from SSH

If you find that you have accidentally been locked out of your WHM/cPanel server by Brute Force Detection, you can log in to your Server or VPS via SSH and run the following command to clear the brute force log:

# echo “delete from brutes; delete from logins;” | mysql cphulkd

Monday, February 10, 2014

How to uninstall Trendy Site Builder

Quick tutorial to remove trendy site builder.

cd /usr/local/cpanel/base/frontend/x3
rm -rf trendysitebuilder
rm -f trendysitebuilder.tar.gz
rm -f /usr/local/cpanel/Cpanel/trendysitebuilder.pm
cd /usr/local/cpanel/whostmgr/docroot/cgi
rm addon_trendysitebuilder.php
rm -rf trendysitebuilder
/usr/local/cpanel/bin/unregister_cpanelplugin /usr/local/cpanel/bin/trendysitebuilder.cpanelplugin
rm -f/usr/local/cpanel/bin/trendysitebuilder.cpanelplugin
/usr/local/cpanel/bin/rebuild_sprites

Thursday, January 23, 2014

Disabling an email account

How can a particular email account be ‘disabled’ temporarily. Note that the email account should not be ‘deleted’ ? Is this possible at all via cPanel?

There is no direct functionality in cPanel at the moment for this. This feature might be added at a later stage.
However, you can achieve this functionality by modifying a few entries via SSH.

Comment out the entries related to the particular email account in the following locations:
/home/user/etc/domainname/passwd
/home/user/etc/domainname/shadow
/home/user/etc/domainname/quota

Make sure that you just comment them and NOT delete them as you might need them back later.

How to find the number of user accounts via shell

There is no control panel installed on the server. So, how can the total number of user accounts on the system be determined?

Use the following command to find the total number of accounts on the system :
cat /etc/passwd | wc -l
Note : This will also include system accounts like root, mail etc.
To list all the accounts on the system then use the following :
cat /etc/passwd | cut -d”:” -f1

How to unblock IP address blocked by Brute force

METHOD to unblock all the IP addresses:

Command to disable cPHulk:

root@bigbang [~]# /usr/local/cpanel/bin/cphulk_pam_ctl – -disable
Command to enable cPHulk:
root@bigbang [~]# /usr/local/cpanel/bin/cphulk_pam_ctl – -enable


Removing blocked IP addresses manually from cPHulk’s database:

1.first login into mysql
#mysql

2.then : use cphulkd;
mysql> use cphulkd;

3.select * from brutes;
mysql> SELECT * FROM brutes WHERE `IP`=’xxx.xxx.xxx.xxx’;

4.Finally
mysql> DELETE FROM brutes WHERE `IP`=’xxx.xxx.xxx.xxx’;

Tuesday, November 26, 2013

How to change your hostname with SSH

If you’ve worked in the admin world for any length of time, you’ve probably run into an instance where you needed to change the hostnames on your server to match some corporate naming standard, but you can’t have downtime either.

Changing the Hostname


First, you must change the config file that controls this. The actual file and its location will vary across distributions. In the Redhat derivatives, the file to modify is /etc/sysconfig/network so vi this file and change the line that reads HOSTNAME=

Log into PuTTY using your username (usually root) and password

  1. Type "cd /etc/sysconfig/" to take you to the sysconfig folder
  2. Type "vi network" to open your network settings
  3. Type "i" on your keyboard and update your HOSTNAME
  4. Press "ESC" on the keyboard
  5. Save the new configuration by typing ":wq!"
  6. Finally, log off and reboot

Wednesday, September 4, 2013

How to Backup and Restore Individual cPanel Account via SSH

Backing up your hosting account is very necessary for your business to survive on Internet. Whether it is a small or large business, you must backup all of your data regularly at least once a week. cPanel provides some great ready made scripts which will help you make your tasks more easy. Commands such as pkgacct is basically used for backing up cpanel web hosting accounts and restorepkg for restoring cpanel accounts via the SSH or command line interface.

How to create backup of Individual cPanel Account via SSH?

Step 1: Log-in to the SSH as Root user.

Step 2: Enter the following command string on the command line interface:

    /scripts/pkgacct username

[Note: The account backup will be created in the current directory you are in.]

How to Restore the Individual cPanel Account via SSH?

Step 1: To restore the cPanel account backups, enter the following command

    /scripts/restorepkg username

[Note: In order to restore the data, you need to be in the directory where the backup file is stored.]

Tuesday, July 2, 2013

How to install mod_evasive in cPanel server

Please follow the procedure given below to install and configure  mod_evasive in  cPanel server with apache 2.2.

Download the   latest source file from http://www.zdziarski.com

# cd /usr/local/src/
# wget /blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz
# tar -xvzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive/
# /usr/local/apache/bin/apxs -cia mod_evasive20.c
 
Now create a file named  /usr/local/apache/conf/mod_evasive.conf and add the following lines

# cat /usr/local/apache/conf/mod_evasive.conf
LoadModule evasive20_module   modules/mod_evasive20.so
<IfModule mod_evasive20.c>
DOSHashTableSize    3097
DOSPageCount        2
DOSSiteCount        50
DOSPageInterval     1
DOSSiteInterval     1
DOSBlockingPeriod   10
</IfModule>
Now include the above file inside  /usr/local/apache/conf/includes/pre_main_global.conf
Include "/usr/local/apache/conf/mod_evasive.conf"
Now rebuild httpd.conf
/scripts/rebuildhttpdconf
Now restart apache
/scripts/restartsrv httpd

Monday, July 1, 2013

How To Reset A Kloxo Or LxAdmin Password From SSH

When your VPS is installed by us with Kloxo or LXadmin the password will 'admin' and the username 'admin' too.
Note: if you reinstall yourself it will also be 'admin'.
If you still can't login then:

1) Login via SSH

2) cd /usr/local/lxlabs/kloxo/httpdocs

or

2) cd /usr/local/lxlabs/lxadmin/httpdocs

3) /usr/bin/lphp.exe  ../bin/common/resetpassword.php master NEWPASSWORD

Now try your password again.

Sunday, June 30, 2013

How to enable SSH/Shell Access in cPanel

Linux distros include SSH client software by default or it can be easily installed with
'apt-get install openssh-client' or 'yum install openssh-clients' depending on your package manager.

To access your shell with SSH from Linux perform the following steps:

1. Login to cPanel and go to Security > SSH/Shell Access to generate SSH key pair.

2. Click Manage SSH Keys > Generate a New Key. You should use a password to protect the key. You will be asked the password each time you use the key.

3. In Public Keys section click 'Manage Authorization' and 'Authorize'

4. In Private Keys section click Vew/Download then download the key (id_dsa or id_rsa) to your PC.

5. Save it to ~/.ssh directory on your linux machine under a meaningful name to not overwrite your existing keys for example id_dsa.myjavahost

6. Now make sure permissions are correct on the key (one time task) and connect (you will be prompted for the password you setup in step #2):

mypc:~$ chmod 600 .ssh/id_dsa.myjavahost
mypc:~$ ssh -p1033 -i .ssh/id_dsa.myjavahost yourusername@yourservername
Enter passphrase for key '.ssh/id_dsa.myjavahost':

You should be logged in now.

Wednesday, March 27, 2013

How To Change Default SSH Port 22 in Linux

By default, SSH listens for connections on port 22. Attackers use port scanner software to see whether hosts are running an SSH service. It’s wise to change the SSH port to a number higher than 1024 because most port scanners by default don’t scan high ports.

root@localhost[~]# cd /etc/ssh/

2) Edit file: sshd_config

root@localhost [/etc/ssh]# vi sshd_config
Change port on below line in sshd_config file:
“#Port 22″ should be changed to “Port 4765 ”
3) You should not permit root logins via SSH, because this is a big and unnecessary security risk. If an attacker gains root login for your system, he can do more damage than if he gains normal user login.

Configure SSH server so that root user is not allowed to log in. Find the line that says:
“PermitRootLogin yes” should be changed to “PermitRootLogin no”

You can then log in with any other defined user and switch to user root if you want to become a superuser.

4) Once all the changes done, restart the ssh services:
root@localhost [/etc/ssh]# service sshd restart
Above provided steps will change default ssh port 22 to other port like 4765.

Make changes to the firewall with blocking Port 22 and allowing the new Port number used by SSH.