Tuesday, October 22, 2013

How to add port to firewall in centos

You can just open /etc/sysconfig/iptables file and add the below line and change the port which port you want to allow from firewall.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

Save the file and restart iptables service.

Open the terminal and run the following command /etc/init.d/iptables restart.

Linux Terminal Command Reference

System Info

date – Show the current date and time
cal – Show this month's calendar
uptime – Show current uptime
w – Display who is online
whoami – Who you are logged in as
finger user – Display information about user
uname -a – Show kernel information
cat /proc/cpuinfo – CPU information
cat /proc/meminfo – Memory information
df – Show disk usage
du – Show directory space usage
free – Show memory and swap usage

Keyboard Shortcuts

Enter – Run the command
Up Arrow – Show the previous command
Ctrl + R – Allows you to type a part of the command you're looking for and finds it
Ctrl + Z – Stops the current command, resume with fg in the foreground or bg in the background
Ctrl + C – Halts the current command, cancel the current operation and/or start with a fresh new line
Ctrl + L – Clear the screen
command | less – Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow
!! – Repeats the last command
command  !$ – Repeats the last argument of the previous command
Esc + . (a period) – Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command
Ctrl + A – Return to the start of the command you're typing
Ctrl + E – Go to the end of the command you're typing
Ctrl + U – Cut everything before the cursor to a special clipboard, erases the whole line
Ctrl + K – Cut everything after the cursor to a special clipboard
Ctrl + Y – Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to
Ctrl + T – Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
Ctrl + W – Delete the word / argument left of the cursor in the current line
Ctrl + D – Log out of current session, similar to exit

Learn the Commands

apropos subject – List manual pages for subject
man -k keyword – Display man pages containing keyword
man command – Show the manual for command
man -t man | ps2pdf - > man.pdf  – Make a pdf of a manual page
which command – Show full path name of command
time command – See how long a command takes
whereis app – Show possible locations of app
which app – Show which app will be run by default; it shows the full path

Searching

grep pattern files – Search for pattern in files
grep -r pattern dir – Search recursively for pattern in dir
command | grep pattern – Search for pattern in the output of command
locate file – Find all instances of file
find / -name filename – Starting with the root directory, look for the file called filename
find / -name ”*filename*” – Starting with the root directory, look for the file containing the stringfilename
locate filename – Find a file called filename using the locate command; this assumes you have already used the command updatedb (see next)
updatedb – Create or update the database of files on all file systems attached to the Linux root directory
which filename – Show the subdirectory containing the executable file  called filename
grep TextStringToFind /dir – Starting with the directory called dir, look for and list all files containingTextStringToFind

File Permissions

chmod octal file – Change the permissions of file to octal, which can be found separately for user, group, and world by adding: 4 – read (r), 2 – write (w), 1 – execute (x)
Examples:
chmod 777 – read, write, execute for all
chmod 755 – rwx for owner, rx for group and world
For more options, see man chmod.

File Commands

ls – Directory listing
ls -l – List files in current directory using long format
ls -laC – List all files in current directory in long format and display in columns
ls -F – List files in current directory and indicate the file type
ls -al – Formatted listing with hidden files
cd dir – Change directory to dir
cd – Change to home
mkdir dir – Create a directory dir
pwd – Show current directory
rm name – Remove a file or directory called name
rm -r dir – Delete directory dir
rm -f file – Force remove file
rm -rf dir – Force remove an entire directory dir and all it’s included files and subdirectories (use with extreme caution)
cp file1 file2 – Copy file1 to file2
cp -r dir1 dir2 – Copy dir1 to dir2; create dir2 if it doesn't exist
cp file /home/dirname – Copy the file called filename to the /home/dirname directory
mv file /home/dirname – Move the file called filename to the /home/dirname directory
mv file1 file2 – Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directoryfile2
ln -s file link – Create symbolic link link to file
touch file – Create or update file
cat > file – Places standard input into file
cat file – Display the file called file
more file – Display the file called file one page at a time, proceed to next page using the spacebar
head file – Output the first 10 lines of file
head -20 file – Display the first 20 lines of the file called file
tail file – Output the last 10 lines of file
tail -20 file – Display the last 20 lines of the file called file
tail -f file – Output the contents of file as it grows, starting with the last 10 lines

Compression

tar cf file.tar files – Create a tar named file.tar containing files
tar xf file.tar – Extract the files from file.tar
tar czf file.tar.gz files – Create a tar with Gzip compression
tar xzf file.tar.gz – Extract a tar using Gzip
tar cjf file.tar.bz2 – Create a tar with Bzip2 compression
tar xjf file.tar.bz2 – Extract a tar using Bzip2
gzip file – Compresses file and renames it to file.gz
gzip -d file.gz – Decompresses file.gz back to file

Printing

/etc/rc.d/init.d/lpd start – Start the print daemon
/etc/rc.d/init.d/lpd stop – Stop the print daemon
/etc/rc.d/init.d/lpd status – Display status of the print daemon
lpq – Display jobs in print queue
lprm – Remove jobs from queue
lpr – Print a file
lpc – Printer control tool
man subject | lpr – Print the manual page called subject as plain text
man -t subject | lpr – Print the manual page called subject as Postscript output
printtool – Start X printer setup interface

Network

ifconfig – List IP addresses for all devices on the local machine
ping host – Ping host and output results
whois domain – Get whois information for domain
dig domain – Get DNS information for domain
dig -x host – Reverse lookup host
wget file – Download file
wget -c file – Continue a stopped download

SSH

ssh user@host – Connect to host as user
ssh -p port user@host – Connect to host on port port as user
ssh-copy-id user@host – Add your key to host for user to enable a keyed or passwordless login

User Administration

adduser accountname – Create a new user call accountname
passwd accountname – Give accountname a new password
su – Log in as superuser from current login
exit – Stop being superuser and revert to normal user

Process Management

ps – Display your currently active processes
top – Display all running processes
kill pid – Kill process id pid
killall proc – Kill all processes named proc (use with extreme caution)
bg – Lists stopped or background jobs; resume a stopped job in the background
fg – Brings the most recent job to foreground
fg n – Brings job n to the foreground

Installation from source

./configure
make
make install
dpkg -i pkg.deb – install a DEB package (Debian / Ubuntu / Linux Mint)
rpm -Uvh pkg.rpm – install a RPM package (Red Hat / Fedora)

Stopping & Starting

shutdown -h now – Shutdown the system now and do not reboot
halt – Stop all processes - same as above
shutdown -r 5 – Shutdown the system in 5 minutes and reboot
shutdown -r now – Shutdown the system now and reboot
reboot – Stop all processes and then reboot - same as above
startx – Start the X system

Monday, October 14, 2013

How to install MySQL on Ubuntu/Debian

It may seem easy for some, but for others, installing MySQL on Ubuntu or Debian Linux is not an easy task. This article explains to you how to install the MySQL Server and Client packages on a Ubuntu/Debian system.

First of all, make sure your package management tools are up-to-date. Also make sure you install all the latest software available.

sudo apt-get update
sudo apt-get dist-upgrade
After a few moments (or minutes, depending on the state of your system), you’re ready to install MySQL. ~ By default, recent Ubuntu/Debian systems install a MySQL Server from the 5-branch. This is a good thing, so don’t worry.

First, install the MySQL server and client packages:

sudo apt-get install mysql-server mysql-client
When done, you have a MySQL database read to rock ‘n roll. However, there’s more to do.

You need to set a root password, for starters. MySQL has it’s own user accounts, which are not related to the user accounts on your Linux machine. By default, the root account of the MySQL Server is empty. You need to set it. Please replace ‘mypassword’ with your actual password and myhostname with your actual hostname.

sudo mysqladmin -u root -h localhost password 'mypassword'
sudo mysqladmin -u root -h myhostname password 'mypassword'
Now, you probably don’t want just the MySQL Server. Most likely you have Apache+PHP already installed, and want MySQL to go with that. Here are some libraries you need to install to make MySQL available to PHP:

sudo apt-get install php5-mysql
Or for Ruby:

sudo apt-get install libmysql-ruby
You can now access your MySQL server like this:

mysql -u root -p
Have fun using MySQL Server.

How to install Oracle Java in Linux

Check to see if your Ubuntu Linux operating system architecture is 32-bit or 64-bit, open up a terminal and run the following command below.
getconf LONG_BIT

It will print the exact number 32 or 64.

Download the Oracle Java JDK/JRE for Linux. Make sure you select the correct compressed binaries for your system architecture 32-bit or 64-bit (which end in tar.gz).
For example, if you are on Ubuntu Linux 32-bit operating system download 32-bit Oracle Java binaries.
For example, if you are on Ubuntu Linux 64-bit operating system download 64-bit Oracle Java binaries.

Important Information: 64-bit Oracle Java binaries do not work on 32-bit Ubuntu Linux operating systems, you will receive multiple system error messages, if you attempt to install 64-bit Oracle Java on 32-bit Ubuntu Linux.

Copy the Oracle Java binaries into the /usr/local/java directory. In most cases, the Oracle Java binaries are downloaded to: /home/"your_user_name"/Downloads.

32-bit Oracle Java on 32-bit Ubuntu Linux installation instructions:
Type/Copy/Paste: cd /home/"your_user_name"/Downloads
Type/Copy/Paste: sudo cp -r jdk-7u40-linux-i586.tar.gz /usr/local/java
Type/Copy/Paste: sudo cp -r jre-7u40-linux-i586.tar.gz /usr/local/java
Type/Copy/Paste: cd /usr/local/java

64-bit Oracle Java on 64-bit Ubuntu Linux installation instructions:
Type/Copy/Paste: cd /home/"your_user_name"/Downloads
Type/Copy/Paste: sudo cp -r jdk-7u40-linux-x64.tar.gz /usr/local/java
Type/Copy/Paste: sudo cp -r jre-7u40-linux-x64.tar.gz /usr/local/java
Type/Copy/Paste: cd /usr/local/java

Unpack the compressed Java binaries, in the directory /usr/local/java
32-bit Oracle Java on 32-bit Ubuntu Linux installation instructions:
Type/Copy/Paste: sudo tar xvzf jdk-7u40-linux-i586.tar.gz
Type/Copy/Paste: sudo tar xvzf jre-7u40-linux-i586.tar.gz

64-bit Oracle Java on 64-bit Ubuntu Linux installation instructions:
Type/Copy/Paste: sudo tar xvzf jdk-7u40-linux-x64.tar.gz
Type/Copy/Paste: sudo tar xvzf jre-7u40-linux-x64.tar.gz

Double-check your directories. At this point, you should have two uncompressed binary directories in /usr/local/java for the Java JDK/JRE listed as:
Type/Copy/Paste: ls -a
jdk1.7.0_40
jre1.7.0_40

Edit the system PATH file /etc/profile and add the following system variables to your system path. Use vi, gedit or any other text editor, as root, open up /etc/profile.
Type/Copy/Paste: sudo gedit /etc/profile
or
Type/Copy/Paste: sudo vi /etc/profile

Scroll down to the end of the file using your arrow keys and add the following lines below to the end of your /etc/profile file:
Type/Copy/Paste:

export JAVA_HOME=/usr/local/java/jdk1.7.0_40
export PATH=$PATH:$JAVA_HOME/bin

Save the /etc/profile file and exit.

Reload your system wide PATH /etc/profile by typing the following command:
Type/Copy/Paste: . /etc/profile
Note your system-wide PATH /etc/profile file will reload after reboot of your Ubuntu Linux system

Test to see if Oracle Java was installed correctly on your system. Run the following commands and note the version of Java:

A successful installation of 32-bit Oracle Java will display:
Type/Copy/Paste: java -version
This command displays the version of java running on your system
You should receive a message which displays:
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b40)
Java HotSpot(TM) Server VM (build 23.1-b03, mixed mode)
Type/Copy/Paste: javac -version
This command lets you know that you are now able to compile Java programs from the terminal.
You should receive a message which displays:
javac 1.7.0_40

A successful installation of Oracle Java 64-bit will display:
Type/Copy/Paste: java -version
This command displays the version of java running on your system
You should receive a message which displays:
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b40)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
Type/Copy/Paste: javac -version
This command lets you know that you are now able to compile Java programs from the terminal.
You should receive a message which displays:
javac 1.7.0_40

Congratulations, you just installed Oracle Java on your Linux system. Now reboot your Ubuntu Linux system. Afterwards, your system will be fully configured for running and developing Java programs. Later on you may want to try compiling and running your own Java programs by following this article How to Create your First Java Program on Ubuntu Linux


Quickly Enable Root Login in Ubuntu 12.10

Here’s a quick way to login as root in Ubuntu 12.10. This is not recommended as the root user account is disabled for a reason.
In a perfect world, no one should login with total administrator rights (root user) in Ubuntu. But since we’re not in a perfect world, this brief tutorial is going to show you how to quickly enable root login in Ubuntu 12.10
Objectives:
  • Login as Root (Administrator) in Ubuntu 12.10
  • Enjoy!
To get started, press Ctrl – Alt – T on your keyboard to open the terminal. When it opens, run the commands below to create a root password.
sudo passwd root
Next, run the commands below to enable root login in Ubuntu 12.10
sudo vi /etc/lightdm/lightdm.conf
add the below line end of the file.
greeter-show-manual-login=true
save the file and restart the system. In the next boot you can see login label in the login screen.