Disable ftp account of a specific user

If you want to disable ftp account of any user, you should follow these steps.

The process does not prevent user to log into shell prompt. User can log into shell prompt as well as execute the commands but he can't use ftp services.

If you are using debian or ubuntu. Run following command.
$ echo username >> /etc/ftpusers
If you are using centos or fedora. Run following command.
$ echo username >> /etc/vsftpd/ftpusers
The user will not be able to access ftp account.

If you do not want to use command line. Open file /etc/ftpusers or /etc/vsftpd/ftpusers (according to your distribution) and add username in the list.
To Allow access :
Just remove the username from the file ftpusers.
Restart vsftpd.

Enable ftp account of root

By Default, root is not able to access ftp because it's name in the list of /etc/ftpusers or /etc/vsftpd/ftpusers
Remove root from the list.
Restart vsftpd.
root will be able to log-in using ftp.

If you are using CentOS, fedora or RHEL and still you are not able to log in as root in your ftp server.
Add following line in the file vsftpd.conf
userlist_deny=YES
Remove user root fin the file /etc/vsftpd/user_list and restart vsftpd.
root should be able to log-in using ftp.

Install webmin on Linux - CentOS, Fedora, Debian or Ubuntu

Download webmin from here.

1) If your Linux distribution is yum based like CentOS or fedora,
Download rpm file of webmin and install it using 
$ sudo rpm -ivh webmin-installation-filename.rpm
If your Linux distribution is dpkg(deb) based like ubuntu or debian,
Download deb file of webmin and install it using 
$ sudo dpkg -i webmin-installation-filename.deb

2) Now webmin is installed and we can access it using port 10000, Open it.
https://localhost:10000

3) If your firewall prevents to access webmin using other system of same LAN, you should define port 10000 in iptables.
Add following line in /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 10000 -j ACCEPT

4) Restart iptables
$ sudo service iptables restart

5) Now you can access it using
https://ip-of-the-server:10000

6) username, password of webmin is same as root's username & root's password of the server.


webmin - Security Warning

Warning! Webmin has detected that the program 
https://IP-address:10000/right.cgi?open=system&open=status was linked to from an unknown URL, which appears to be outside the Webmin server. This may be an attempt to trick your server into executing a dangerous command.

First Method :
  • Login as root, and edit the /etc/webmin/config file.
  • Find the line referers_none=1 and change it to referers_none=0.
  • Save the file.
Second Method :
  • Login to Webmin normally.
  • Go to the Webmin Configuration module.
  • Click on the Trusted Referrers icon.
  • Check the Trust links from unknown referrers box, and click Save.
Final Method :
If above both methods do not work, follow this.
Open following link in chrome
Select radio button NO for Referrer checking enabled?
Now try again.

webmin - Error - Bad Request

Open webmin url with https
The correct url is https://localhost:10000/webmin

Log-in as root on Linux Terminal

I am going to show you three most used methods to log-in as root.

First way :
If you have sudo privileges as a user, you can use following command to log-in as root on terminal.
$ sudo -i
It asks for your (user's) password. After enter your password, you can log-in as root on terminal.

Second way :
$ su - or $ su - root
It asks for root's password. If you know root's password, you can log-in as root.

Third way:
You can log-in as root using secure shell (ssh)
$ ssh ip-of-the-server

If client and server are two different systems, the first two methods do not work to log-in as root on server. Only third method will work.

If client and server are in same system (root and users are in same system) , the first two methods do not require internet to log-in as root on terminal.

Third method requires internet to log-in as root on terminal.

Disable sudo privileges for user

If you want, user should not execute command with sudo.
To remove sudo permissions for user, follow the process.

1. Change the group of user. To see how to change the group of a user click here.

2. Do not define the group in file /etc/sudoers
     A group-name is started with symbol % in  /etc/sudoers
     Comment the line in /etc/sudoers
    #%group-name ALL=(ALL) ALL
Above line without comment gives sudo permission to all users of the group.
If you comment this line, no user of the group can use sudo while executing any command.

3. Now whenever user tries to run command with sudo, it says
 Error - username is not in the sudoers file. This incident will be reported.

Add username & group in sudoers file

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


Open the file /etc/sudoers, Add following line in it
username ALL=(ALL) ALL
If your username is john, the line should be
john ALL=(ALL) ALL

If you want to add whole group as sudoers.
%group-name ALL=(ALL) ALL
where % indicates the name is a group.

If your group-name is wheel, the line should be
%wheel ALL=(ALL) ALL

Run multiple commands in Linux Launcher

If you want to run multiple commands in launcher.




Example:- If you want to stop apache2 (httpd) & mysql (mysqld) simultaneously. You would use 

service apache2 stop && service mysql stop
or
service httpd stop && service mysqld stop

But unfortunately it won't work in Launcher. It runs the first command but does not execute second.

To run multiple commands as a Launcher, you should use
sh -c "service apache2 start && service mysql start"
Now when you run launcher, it executes all commands.

If you want to run three commands,
sh -c "service apache2 start && service mysql start && cat > redirect"
In above example, it would start both services as well as create a file redirect.

Run sudo without asking user password

No password for sudo


Open file /etc/sudoers  and uncomment following line.
%sudo ALL=NOPASSWD: ALL
Save the file.

Now if you run commands with sudo, it does not ask user password.

.htaccess - Error 500 - Internal Server Error

Error 500 - Internal Server Error



To remove this error, check the content of .htaccess. It should be like this. 

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /your-web-project-directory-name/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /your-web-project-directory-name/index.php [L] <IfModule>

If Apache can’t understand any line in your .htaccess, it will cause an error.
When you try to access your web page, it generates the error.

A garbage line in .htaccess can create Internal Server Error.

Example:
Create a file name .htaccess, write your name into it, save it and put it in your web project directory. Now try to access the web page, it will give this error.

Define rewrite rule carefully in your .htaccess. If you write anything in .htaccess which apache can't understand, it will be the reason of Internal Server Error.

If rewrite module is not enabled and you are using rewrite engine in the .htaccess, you may have this error. To find a solution, click here or you can find another solution here.

.htaccess issue - html links are not working

.htaccess - Menu Links are not working


.htaccess links defined in rewrite-rules are not working in apache2

1) Enable rewrite module
   $ sudo a2enmod rewrite    $ service apache2 restart


2) These lines should be in /etc/apache2/apache2.conf
AccessFileName .htaccess <Directory /var/www>     AllowOverride All     #AllowOverride None </Directory> 
Restart apache2.

3) Enter following lines in /etc/apache2/httpd.conf

<Directory /var/www/project-name>     AddHandler cgi-script .cgi     Options +Indexes +ExecCGI     AllowOverride all </Directory> 

4) "AllowOverride all" should be uncommented in apache2.conf or httpd.conf.

.htaccess issue - The character encoding of the HTML document was not declared

Error: The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.Source File: http://localhost/path/of/the/project/    Line: 0


The website dos not load the css and it looks distorted when .htaccess file is used for web project.

To solve this error:
Add following line in your apache configuration file.
/etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf (according to your linux distribution)
AddHandler application/x-httpd-php .htm

Restart Apache.

Enable authentication in apache2 using .htaccess

.htaccess is not working in apache2 :

If you have put .htaccess in your web project directory and it does not ask for username & password.
Follow this.

1) Check following directives in /etc/apache2/sites-available/default
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>
   Where /var/www is path of the directory where you keep your web projects.

2) Add following directive in httpd.conf
<Directory /your/path/of/the/project> AllowOverride All </Directory>

3) Restart apache2.



Create .htaccess & .htpasswd files for your web projects


Make secure your web Project in Apache using .htaccess

Create a filename .htaccess and put following content in it.

AuthName "Restricted Area"  AuthType Basic  AuthUserFile /opt/lampp/.htpasswd  AuthGroupFile /dev/null  require valid-user

Create a filename .htpasswd and generate a password using following site.
http://www.htaccesstools.com/htpasswd-generator/

Enter Username and Password. Click on create.
Now copy the generated line and paste into your .htpasswd file.
The .htpasswd file contains only this, a username:encrypted password

root:$apr1$7I58.7SX$zkt0..fl0ZBwU3ShGpDjZ1

a) In .htaccess file, AuthUserFile is path of the directory, where .htpasswd file is placed.
In above example I am trying to make my phpmyadmin password protected that's why I have put my .htpasswd file in parent directory and .htaccess file in /opt/lampp/phpmyadmin.
Now when I try to access http://localhost/phpmyadmin , It asks password to open the phpmyadmin.

b) Put the .htpasswd file in parent directory of the password protected directory and place the .htaccess in directory which you want to protect.

c) In above example username is root & password is linux.

d) It asks for password when directory is accessed through browser.

e) Once you put the log-in details and open your website, you have to close the browser completely to see the log-in box again. It does not ask the password every time you refresh the page.


To protect a single file instead of whole directory


If you do not want to protect whole directory instead of you want to protect single file.
Example : If you or anyone in LAN access your phpinfo.php , you want it should ask password.
In this case the contents of .htaccess file is
AuthName "Name of Page" AuthType Basic AuthUserFile /opt/lampp/htdocs/.htpasswd <Files "phpinfo.php"> require valid-user </Files>

Put the .htaccess in the directory where file you want to  protect is placed.

In this example, I want to protect my phpinfo.php. This file is placed in /opt/lampp/htdocs/xampp that's why I have put the .htaccess in xampp directory and .htpasswd in parent directory of xampp.

It will ask for password when user tries to access that file using browser.
http://localhost/xampp/phpinfo.php
But it will not ask for password if you try to access the directory.

XAMPP: Another web server daemon is already running / XAMPP: Another MySQL daemon is already running.


XAMPP: Another web server daemon is already running.
XAMPP: Another MySQL daemon is already running.



There are two ways to remove these errors.
1) Stop the running services
$ sudo service service-name stop
If you are using Debian or Ubuntu :
$ sudo service apache2 stop $ sudo service mysql stop
If you are using CentOS , RHEL or Fedora :
$ sudo service httpd stop $ sudo service mysqld stop

2) Kill the running services

Now here is the second method.

XAMPP-web server works on port 80 and XAMPP-MySQL works on port 3306.

We have to find the services of respective ports and kill them.

Run following command in terminal
$ sudo netstat -lnp | grep -e :80 -e :3306

It will show you all processes of port 80 & 3306 like this
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      15268/apache2   
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      14699/mysqld 

Now kill them using
$ sudo killall -9 process-name

It shows the process name beside pid (process id). In above example pid is 15268 & process-name is apache2. Another pid is 14699 & process-name is mysqld.

To kill the above processes, Run
$ sudo killall -9 apache2 $ sudo killall -9 mysqld
Now if you start XAMPP, it does not give process running error.

But if it still gives, kill the running process again.

You can kill the processes using pid too.
$ sudo kill -9 pid

To kill the above processes, Run
$ sudo kill -9 15268 $ sudo kill -9 14699

#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)

phpMyAdmin is giving error
#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)

Probably there are two mysql running. Open the terminal and run
$ service mysql stop
or
$ service mysqld stop
(according to your Linux distribution)
Now restart lampp and try to open phpMyAdmin.

Make sure you have following code in your /opt/lampp/phpmyadmin/config.inc.php
$cfg['Servers'][$i]['connect_type'] = 'tcp';
If not, add above line in config.inc.php and Restart mysql.

If you are still facing the problem. Add this line in your config.inc.php too.
$cfg['Servers'][$i]['socket'] = '/var/run/mysql/mysql.sock';
and Restart mysql.

If you are still facing the problem, Make following changes in your config.inc.php

change 
$cfg['Servers'][$i]['host'] = 'localhost';
to 
$cfg['Servers'][$i]['host'] = '127.0.0.1';
Now restart mysql and open phpmyadmin.

If you are still facing the problem, check permission of the file /opt/lampp/phpmyadmin/config.inc.php, it should not be less than 755.
Set it to 755.
Run following command.
$ sudo chmod 755 /opt/lampp/phpmyadmin/config.inc.php
Now restart LAMPP and try to open phpmyadmin again.
http://localhost/phpmyadmin

XAMPP: Couldn't start MySQL

Remove Error : XAMPP: Couldn't start MySQL

Run following commands in terminal
$ sudo chown -hR root /opt/lampp $ sudo chmod -R 777 /opt/lampp $ sudo /opt/lampp/lampp restart
After running above commands when you try to start XAMPP and it gives following error :

"Warning: World-writable config file ‘/opt/lampp/etc/my.cnf’ is ignored"

To Remove above error, Run following command in terminal
$ sudo chmod 755 /opt/lampp/etc/my.cnf

After running above command when you try to start XAMPP again and it gives following error :

Wrong permissions on configuration file, should not be world writable!

To Remove above error, Run following command in terminal
$ sudo chmod 755 /opt/lampp/phpmyadmin/config.inc.php

Recover /etc/passwd file in Linux


/etc/passwd is deleted accidently, Recover the file.

There is a backup file of /etc/passwd in same directory with name passwd-
$ sudo cp /etc/passwd- /etc/passwd $ sudo chmod 644 /etc/passwd

Lock the file using
$ sudo pwck -q

If you are not root user and do not use sudo before pwck -q, it will give error
pwck: cannot lock /etc/passwd; try again later.


External USB Hard Disk (HDD) NTFS not detected in CentOS

External (USB) hard disk is not detected :

Install NTFS package in centOS


$ yum install fuse fuse-ntfs-3g

If it does not work, download rpm file and install using
ftp://ftp.muug.mb.ca/mirror/fedora/epel/6/x86_64/ntfs-3g-2011.4.12-5.el6.x86_64.rpm


$ rpm -i filename

Change htdocs path in XAMPP

Here in this example, I am showing you to change the php project directories path from /opt/lampp/htdocs to /var/www

1) Open file /opt/lampp/etc/httpd.conf and change following line

DocumentRoot "/opt/lampp/htdocs"
to
DocumentRoot "/var/www"

2) Now search following line in same file (/opt/lampp/etc/httpd.conf)
and change

# This should be changed to whatever you set DocumentRoot to.
<Directory "/opt/lampp/htdocs">

to
# This should be changed to whatever you set DocumentRoot to. <Directory "/var/www">
(Above line is commented, it has been mentioned to find directive easily)

3) Restart the XAMPP.

4) If virtual hosts have been defined, change the path in /opt/lampp/etc/extra/httpd-vhosts.conf too.
Otherwise above steps will not work.

or if you want to remove virtual hosts, just comment following line in /opt/lampp/etc/httpd.conf
# Include etc/extra/httpd-vhosts.conf
5) Restart the XAMPP.

6) After following above process, if it throws php code in browser.
Uncomment following line in the file /opt/lampp/etc/httpd.conf
Include etc/extra/httpd-xampp.conf
This line should not be commented. It means there should be no Hash '#' symbol at start of the line.

7) If it gives Internal Server Error or Server Error.
Comment following line in the file /opt/lampp/etc/httpd.conf
# Include etc/extra/httpd-vhosts.conf
& Restart the XAMPP.

Related Posts Plugin for WordPress, Blogger...