Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Open a TCP port in Ubuntu's ufw firewall

Answer:

To open a TCP port, e.g. 8080 in the Ubuntu's UFW firewall (Uncomplicated firewall)

# sudo ufw allow 8080/tcp
# sudo ufw reload

How to generate random password?

Answer:

Install the "makepasswd" package, for example, in Ubuntu, type

sudo apt-get install makepasswd

Then execute command

# makepasswd 

ShdDHNt7z

Or you can use another tool called pwgen

sudo apt-get install pwgen

and execute

# pwgen 8 10

It will generate 10 passwords with length equal to 8

Turn off PHP error messages?

Answer:

In a production server, you should always turn off PHP error messages to be displayed for public, to do so, edit the php.ini

E.g.

vi /etc/php.ini

And turn off display_errors

display_errors = Off

How to perform checksum on a file?

Answer:

You can use the md5sum or shasum commands.

Example

#md5sum test.txt

f1d41356dcabb8d8acefed069b22b0da  test.txt
#shasum test.txt

809970aec0109c5464dd36a3a9a5a9e79f838313  test.txt

md5sum is faster if you perform the command on a very large file, but shasum is more secure since the chance of two different files have the same checksum is smaller.

References:

How to avoid SQL injection in PHP?

Answer:

The easiest method is to use the mysql_real_escape_string function

Example:

$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
mysql_real_escape_string($user),
mysql_real_escape_string($password));

Reference: http://php.net/manual/en/function.mysql-real-escape-string.php