Creating an extracting tar files

The most common compressed archive file format in Linux is the tar.gz format. Tar file is an archive file format. Tar.gz is a compressed tar file.

How to create a compressed tar.gz file from a folder or file in Linux?

In order to create a compressed tar.gz archive from a folder/file we need to run the following tar command:

tar czf new-tar-file-name.tar.gz file-or-folder-to-archive

Here is the command explanation:

  • tar – the tar command.
  • c – create new archive.
  • z – compress the archive using gzip.
  • f – use archive file.
  • new-tar-file-name.tar.gz – the name of the tar.gz to create.
  • file-or-folder-to-archive – the name of the folder we want to archive.

How to create a compressed tar.gz file from multiple files and folders in Linux?

In order to create a compressed tar.gz file from multiple files or/and folders we need to run the same tar command we used when we archived a single file/folder and to append the rest of the files/folders’ names to it.

tar -czf new-tar-file-name.tar.gz file1 file2 folder1 folder2

How to extract a compressed tar.gz file in Linux?

tar -xzf tar-file-name.tar.gz

Here is the command explanation:

  • tar – the tar command.
  • x – extract the archive.
  • z – uncompress the archive using gzip.
  • f – use archive file.
  • tar-file-name.tar.gz – the name of the tar.gz to create.

The tar command will extract all the files/folders in the archive to the current directory.

How to extract a compressed tar.bz2 file in Linux?

Extracting tar.bz2 (bzip2 file) is very similar to the way you extract tar.gz file. Instead of using the -z flag you need to use the -j flag for the bzip2 format
tar -xjf tar-file-name.tar.gz

Here is the command explanation:

  • tar – the tar command.
  • x – extract the archive.
  • j - filter the archive through bzip2
  • f – use archive file.
  • tar-file-name.tar.gz – the name of the tar.gz to create.

The tar command will extract all the files/folders in the archive to the current directory.

Bookmark and Share
Monday, June 1st, 2009 at 12:37

cPanel Icon Missing From WHM List Accounts

I came across an issue for the first time where the cPanel icon was missing in the list accounts section. After digging around WHM, I found where the function was disabled.

  • Log into WHM
  • Select “Tweak Settings”
  • Uncheck the box next to “Disable login with root or reseller password into the users’ cPanel interface. Also disable switch account dropdown in themes with switch account feature”
  • Click save

After hitting save, you can go back to the list account section and the cPanel icon will be back.

Bookmark and Share
Thursday, April 23rd, 2009 at 12:18

pty, ptyp, and tty errors

So I came across this error for the first time today when trying to SSH directly into a clients VPS.

login as: root
root@server’s password:
Server refused to allocate pty
stdin: is not a tty

After a quick google search I came across the fix.

[root@node /]# vzlist -a
VEID      NPROC STATUS  IP_ADDR         HOSTNAME
1337         78 running 69.10.59.80     grumpy.thelinuxnoob.com
[root@node /]# vzctl exec 1337 /sbin/MAKEDEV ptyp
[root@node /]# vzctl exec 1337 /sbin/MAKEDEV tty
[root@node /]# vzctl exec 1337 /sbin/MAKEDEV pty

The issue should now be resolved and you can SSH into the VPS.

Bookmark and Share
Tuesday, March 17th, 2009 at 12:49

Install Perl

Very simple install, only 4 commands via SSH and takes about 20 minutes for the install to complete.

wget http://layer1.cpanel.net/perl588installer.tar.gz
tar -xvzf perl588installer.tar.gz
cd perl588installer
./install

Bookmark and Share
Sunday, March 8th, 2009 at 03:54

Upgrade MySQL4 to MySQL5 on cPanel server

Upgrading MySQL versions is a quick and easy process, not much work involved. Always be sure to make a backup before you start though, just in case the upgrade fails or some other unforeseen issue arises.

cp -Rpf /var/lib/mysql /var/lib/mysql.BAK
Login to WHM –> Tweak Settings –> MySQL -> 5.0  and Save settings
/scripts/mysqlup –force
/scripts/perlinstaller –force Bundle::DBD::mysql
/scripts/realperlinstaller –force DBD::mysql
Recompile PHP

You’re done :)

Bookmark and Share
Saturday, March 7th, 2009 at 23:22

Disable root SSH access

Allowing the root user to login directly is a major security issue, we’ll show you how to disable it so you can still login as root but just not directly, reducing the security issue.

This will force a hacker to have to guess 2 seperate passwords to gain root access.
(you do have 2 seperate passwords for admin and root right?)
What happens is you’ll first need to login as your admin user in SSH, then switch to the super user with the su command to get root.

We also will be forcing the use of SSH protocol 2, which is a newer, more secure SSH protocol
Just a couple more ways to help your server stay safe from the bad guys. If you’re using cPanel make sure you add your admin user to the ‘wheel‘ group so that you will be able to ‘su -‘ to root, otherwise you may lock yourself out of root.

1. SSH into your server as ‘admin‘ and gain root access by su

2. Copy and paste this line to edit the file for SSH logins
pico -w /etc/ssh/sshd_config

3. Find the line
Protocol 2, 1

4. Uncomment it and change it to look like
Protocol 2

5. Next, find the line
PermitRootLogin yes

6. Uncomment it and make it look like PermitRootLogin no

7. Save the file Ctrl+X then Y then enter

8. Now you can restart SSH
/etc/rc.d/init.d/sshd restart

Now, no one will be able to login to root with out first loggin in as admin and ’su -’ to root, and you will be forcing the use of a more secure protocol. Just make sure you remember both passwords!

Bookmark and Share
Friday, March 6th, 2009 at 22:38

Screen in SSH

I’m short on time, but here’s a nice little tutorial on screen in SSH courtesy of Aperiodic.net.

Getting in

start a new screen session: screen
.. with session name: screen -S <name>
attach to a running session: screen -r
.. to session with name: screen -r <name>
the “ultimate attach”: screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)

Escape key

All screen commands are prefixed by an escape key, by default C-a (that’s Control-a, sometimes written ^A). To send a literal C-a to the programs in screen, use C-a a.

Getting out

detach: C-a d
detach and logout (quick exit): C-a D D
exit screen: exit all of the programs in screen.
force-exit screen: C-a C-\ (not recommended)

Help

See help: C-a ? (lists keybindings)

Window Management

create new window: C-a c
change to last-visited active window: C-a C-a (commonly used to flip-flop between two windows)
change to window by number: C-a <number> (only for windows 0 to 9)
change to window by number or name: C-a ' <number or title>
change to next window in list: C-a n or C-a <space>
change to previous window in list: C-a p
see window list: C-a ” (allows you to select a window to change to)
show window bar C-a w (if you don’t have window bar)
close current window: Close all applications in the current window (including shell)
kill current window: C-a k (not recommended)
rename current window: C-a A

Split screen

split display: C-a S
jump to next display region: C-a tab
remove current region: C-a X
remove all regions but the current one: C-a Q

Misc

redraw window: C-a C-l
enter copy mode: C-a [ (also used for viewing scrollback buffer)
paste: C-a ]
monitor window for activity: C-a M
monitor window for silence: C-a _
enter digraph: C-a C-v
lock (password protect) display: C-a x
enter screen command: C-a :

Bookmark and Share
Thursday, March 5th, 2009 at 22:37

Server time keeps resetting

Last night I came across a ticket where a customers time kept resetting on their dedicated server. Typically I would fix the time by using the date command because most of issues I came across the servers were only minutes off. After reading through the clients ticket history I realized that the timezone and minutes were correct, but the hour was still off. After a nice little google search I came across a post on a popular linux forum, where a member had the same issue the client was having. In the post a member suggested creating a symlink for /etc/localtime to point to the clients timezone in the /usr/share/zoneinfo folder. I figured it was worth a shot and tried this fix out, and it worked perfectly :)

Since the client was located in Pakistan, he needed the server to be set to the Asai/Karachi time zone.

root@server [/]# ln -sf /usr/share/zoneinfo/Asia/Karachi /etc/localtime

Before the symlink the time showed in EST but listed the timezone as GMT +5

root@server[/]# date
Mon Jan 26 02:46:24 GMT+5 2009
root@server[/]#

After the symlink the time showed in Asia/Karachi (or GMT +5)

root@server [/]# date
Mon Jan 26 12:48:14 PKT 2009
root@server[/]#

Your localtime file should look like this now:

lrwxrwxrwx  1 root   root       32 Jan 26 12:47 localtime -> /usr/share/zoneinfo/Asia/Karachi

I’m not entirely sure why the date wasn’t correct to begin with as the timezone was correct (+5GMT) when checking with the date command. But, things are fixed now so I really can’t complain since the customer is happy :)

Bookmark and Share
Wednesday, March 4th, 2009 at 22:32

Hide your Shell commands

Today  I came across a neat, but pointless shell command. By running the following in shell, it will hide any commands you run.

root@server2 [/]# stty -echo

In order to disable this mode, simply remove the “-” before echo.

root@server2 [/]# stty echo

I guess there really is no point to the command, though you could always mess with your coworkers if they leave their shell prompt open :)

Bookmark and Share
Tuesday, March 3rd, 2009 at 22:30

Enable PHP5 when PHP4 is default

The following tutorial will show how to enable PHP5 on your site, when Apache has PHP4 as default. I normally do everything through SSH, so here are the steps.

root@thelinuxnoob.com [/]# cd home/thelinux/public_html/
root@thelinuxnoob.com [~/public_html]# nano .htaccess
Add the following line to the .htaccess: AddType application/x-httpd-php5 .php
ctrl + x
ctrl + y
enter
root@thelinuxnoob.com [~/public_html]# cat .htaccess | grep php5
AddType application/x-httpd-php5 .php
root@thelinuxnoob.com [~/public_html]# chmod 644 .htaccess
root@thelinuxnoob.com [~/public_html]# chown thelinux.thelinux .htaccess
root@thelinuxnoob.com [~/public_html]#

Via FTP

Open favorite text editor
AddType application/x-httpd-php5 .php
Save as “.htaccess”
Upload through FTP client

That’s my quick tutorial of the day, tune in next time for more tutorials :)

Bookmark and Share
Monday, March 2nd, 2009 at 22:27