Some times you need to use the find command to look for files that are owner by specific user of group in a directory. The find command has options that allow you to search files like this.

 

How to find files owned by a group

Syntax:

 

directory-or-location : Locate the file in this directory path.

-group {group-name}   : Find the file belongs to group-name.

-name {file-name}     : The file name or a search pattern.

 

For example, we will look for files of directories under the group galaxy

 

For example, we will look for files of directories under the group galaxy and where they have extension .csv

 

How to find files owner by a user in Linux

-is similar to finding groups but we only use the option called user

 

For example, we will look for files of directories under the user AO

 

 

 

In this short article we will see How to SCP an entire folder in Linux. This task is very important to know when you work as a system administrator.

The SCP option that allows us to do this is the -r option, and is stands for:

 

 

Here is how you can SCP an entire folder

 

Here is how you can SCP remotely as well an entire folder

 

 

     In this article we will see how to check all the Linux ports that are opened in Centos / RedHat. If you want to open or close a port for a Linux firewall you have to edit the rules in the iptables configuration. By default iptables firewall stores its configuration at etc/sysconfig/iptables file. You need to edit this file and add rules to open port.

  This task should be a known task by any sysadmins, and is the base for understanding the security rules around your system.

Here are the steps to open the port 12345 using the default visual editor vim:

Open port 12345

Open flle /etc/sysconfig/iptables:

 

Append rule as follows:

 

 

Save and close the file. Restart iptables:

 

Verify that port is open

Run following command:

 

Make sure iptables is allowing port connections:

 

        Hey Junior Geeks,  In this article we will see how to install and configure VirtualBox and then Setup a Linux CentOS box running on your Windows machine with inside VirtualBox.

Use the links below to download the installers:

Download Links:
VirtualBox
https://www.virtualbox.org/

CentOS ISO
https://www.centos.org/download/

 

 When you finished downloading follow the Step by Step How to Video tutorial below

Visit our YouTube Channel for more Free Educational Videos

 

 

In this Article we will see how to create a group on an Linux RedHat system step by step.

Description of the task

Groups allow system administrators to apply certain permissions or access to groups of users. Groups must be created first before you can assign a user to that group. To add a new group, you will use the groupadd command.

Syntax to create Linux Group

The syntax for the groupadd command is:

 

Parameters or Arguments used with the groupadd command

The groupadd command requires the following two parameters:

-g Group_ID
The -g parameter indicates that a group number will follow. This is the group number that will be assigned to this new group. The group number must be unique.
Group_Name
The name of the group you would like to add. Group names should be entered in lowercase and may contain underscores. It is recommended that you do not use the same group name more than once.

Prerequisites

You need an account with sudo administrative privileges. The sudo command is used to provide the superuser privileges required for the groupadd command.

Create a Group

The following steps will guide you through creating a group on an RedHat linux system.

  1. To begin adding a new group to your system, you will need to be logged in using a valid user account.In this tutorial, we have logged in as root on one of the AWS EC2 host.
  2. We will add a new group with a Group ID of 9999  and a Group Name of aousers. To add the group called aousers, we would enter the following command:

    The following screenshot demonstrates what you will see.
  3. When you have entered the command, press the Enter key to execute the command.The sudo command will now prompt you to enter the password for your administrator account.Please note that no characters will show as you type your password. This is normal and is important to preserve the security of your password.After you have entered your password, press the Enter key to continue.
  4. If all goes well, you will see the system prompt appear again without any errors. This indicates that the new group called aousers has been added successfully.

In this step we will check to ensure that the group called aousers was added to the system. Since new groups are added to the end of the system group file called /etc/group, we can use the tail command to verify that the new group was added.

Enter the following tail command after the system prompt to show the last few lines of the system group file:

The following screenshot demonstrates what the command will look like after it is typed.

When you have typed the command, press the Enter key to execute the command.

As seen in the screenshot below, the following line appears at the end of the /etc/group file indicating that the aousers group was created.

Great, you have successfully added a new group to your RedHat Linux system!

Ok, Got tired of windows ? You are in the right place ! We will see how to install Ubuntu on your computer by using a USB memory stick and a bit of your patience.

Let us get started !

What do we need:

 1-   A memory stick with a capacity of at least 2GB. It will be formatted (erased) during this process, so copy any files that you want to keep to another location. They will all be permanently deleted from the memory stick.
2-  A computer that can boot (start-up) from a USB memory stick. Many older computers can’t boot from USB – check the boot options in your BIOS (see Start the Ubuntu installer) to see if yours can.
 3-  A computer with at least 384MB of system memory (RAM), 6GB of available hard disk space and a 700MHz or faster x86 processor. Most Intel and AMD processors are x86 processors. 32-bit and 64-bit processors are supported.
A working Internet connection.

Get a Copy of an Ubuntu ISO

1- Go to www.ubuntu.com/getubuntu/download.

2- Choose your country (or one nearby) from the Download location drop-down list.

3- Click Begin download to download the .iso image file needed to install Ubuntu.

Transfer the ISO to the USB drive.

1- Plug-in your USB memory stick. Go to www.pendrivelinux.com/downloads/Universal-USB-Installer and download the Universal-USB-Installer.exe file. Put it on your Desktop or somewhere convenient.

2- Double-click the file to run it. Click I agree and you will be taken to the Setup Your Selections screen.

Under Step 1, choose the version of Ubuntu you have downloaded, and uncheck Download the ISO.

Under Step 2, click Browse and select and open the .iso file you downloaded.

Under Step 3, select your memory stick from the list (make sure you choose the right one). Check the box next to the list to say that you want to format the drive.
Click Create to put the installer onto your memory stick. The whole process should only take a few minutes. All of the files on the memory stick will be erased.

3- When it has finished, close the Universal USB Installer window and safely remove/eject and unplug your memory stick. This is necessary to make sure all of the files were put on the memory stick properly.

Initiate the Ubuntu installer

1- To start your computer from a memory stick, you might need to change the order of boot devices:

2- Plug-in the memory stick and restart your computer. If your computer boots back into Windows, it is not yet set-up to boot from USB, so continue following these steps.

3- Restart the computer again. As soon as the first text appears on the screen, press the button to enter your BIOS/system setup. There should be a message telling you how to do this. You normally need to press one of the following keys, F10, F11, or F12 (there might be another key for your machine)

4- A BIOS screen should appear. Find the option to change the Boot Order and change the first item in the boot order list to be USB Disk, or similar.  The USB Disk option may have a different name on your computer, for example: Removable Drive; USB-HDD; USB Mass Storage; or USB.

5- After you have changed the boot order, save your changes and restart the computer. It should now start from the memory stick.

Install Ubuntu OS

If you have successfully booted from your memory stick, you should now be looking at the purple Ubuntu boot menu.

To start the Ubuntu installer:

1- Wait a few seconds and Ubuntu will start loading. Otherwise, you can press a key and a boot menu with more options will appear. Press the F5 key to access universal access options like the screen reader and magnifier.

2- After a minute or two, an Install window will appear. Select your language from the list to the left of the screen and click Install Ubuntu .Follow the instructions on the screen to select your country, timezone and keyboard layout.

  3- When you get to the Prepare disk space screen, choose one of the following options to determine how to put Ubuntu on your hard disk:

A – If you want to keep Windows installed and choose whether to start Windows or Ubuntu each time you start the computer, choose Install them side by side. This is called a dual-boot setup. Use the slider on the colored bar at the bottom of the screen to choose how to share disk space between Windows and Ubuntu (Ubuntu should have at least 4 GB of space).

B – If you want to remove Windows and replace it with Ubuntu, choose Erase and use the entire disk. All of the files on the disk will be deleted before ubuntu is put on it, so make sure you have backup copies of anything you wanted to keep.

C – For more complicated disk layouts, choose Specify partitions manually. You can manually add, modify and delete disk partitions using this option.

      4- When you click Forward, you may receive a message saying that the changes will be applied . This normally happens if you resized a partition. If you clickContinue, your hard disk will be changed permanently and you won’t be able to go back. Make sure you’re happy with any changes that you made.

      5- Follow the rest of the instructions to choose a username and password and migrate files and settings from Windows.

      6- Click Install. The installation will begin, and should take 10-20 minutes to complete. When it is finished, choose to restart the computer and then remove your memory stick. Ubuntu should start to load.

Pip is a tool for installing and managing Python packages.

Pip is part of Extra Packages for Enterprise Linux (EPEL), which is a community repository of non-standard packages for the RHEL distribution.

 

 

First, we’ll install the EPEL repository.

Install python-pip and any required packages:

Verify that pip is installed:

 

 

In our last article over AWK “Getting started with AWK” see introduced our self’s with AWK, now let`s try to see how we can create AWK scripts and use them.

Passing your scripts to awk as a command line argument can be very handy for small one-liners, but when it comes to complex, multi-line programs, you’ll definitely want to compose your script in an external file. Awk can then be told to source this script file by passing it the -f option.

See example: 

Where the content of my awk script is:

And my file.txt:

Putting your scripts in their own text files also allows you to take advantage of additional awk features. For example, this multi-line script does the same thing as one of our earlier one-liners, printing out the first field of each line in file.txt.

More complex awk scripts can be written but more about this on the next article .

 

Awk is geared toward text processing and report generation, yet features many well-designed features that allow for serious programming. And, unlike some languages, awk’s syntax is familiar, and borrows some of the best parts of languages like C, python, and bash (although, technically, awk was created before both python and bash). Awk is one of those languages that, once learned, will become a key part of your strategic coding arsenal.

Let’s go ahead and start playing around with awk to see how it works.

awk

The essential organization of an AWK program follows the form:

The pattern specifies when the action is performed. Like most UNIX utilities, AWK is line oriented. That is, the pattern specifies a test that is performed with each line read as input. If the condition is true, then the action is taken. The default pattern is something that matches every line.

See the example here:

You should see the contents of your /etc/fstab file appear before your eyes.

 

When we executed awk, it evaluated the print command for each line in /etc/fstab , in order. All output is sent to stdout, and we get a result identical to catting /etc/fstab.

This time we will do the same thing but with a different awk syntax:

The $0 variable represents the entire current line, so print and print $0 do exactly the same thing.

 

Next example will replace the lines with a string of your choice:

 

Breaking Text

Awk is really good at handling text that has been broken into multiple logical fields, and allows you to effortlessly reference each individual field from inside your awk script. The following script will print out a list of all user accounts on your system:

When we called awk, we use the -F option to specify “:” as the field separator. When awk processes the print $1command, it will print out the first field that appears on each line in the input file.

More strings

As you can see, awk prints out the first and third fields of the /etc/passwd file, which happen to be the username and uid fields respectively.

 

Strings with spaces in between

When you call print this way, it’ll concatenate $1, " ", and $3, creating readable output.

Adding test to the combination

This will become readable output concatenated with the extra text.

 

This ends of first AWK tutorial.  See next tutorial on Using AWK Scripts

 

 

These are some of those critical files for your computer. Without them, your computer will not know where to find any of the partitions or drives on the computer.

Loose this up and you can be dead in the water.

Never make any changes without a good backup copy.

/etc/fstab

In this file there is a description of the various file systems.

Commands like ¨fsck¨ and ¨mount¨ consult this file for the actions they take.
This looks like a complicated description of the files on your host, but it is really simple if you break it down into the parts of each entry.

See below
– In order for certain programs to be able to determine where certain partitions are supposed to be mounted by default, the /etc/fstab file is used.



I will try to bring some clarity in there. Let´s only take the partitions, here for Linux : / and /home and swap.



For the CD-ROM and floppy drive:



You can see the CD-ROM and floppy have the same codes as the Windows partition because they are not Linux default.

For the memory card reader:



Two additional entries are ¨devpts¨ and ¨/proc¨

The devpts file system provides an interface to pseudo-terminal (pty) devices. It is typically mounted at /dev/pts.

The /proc filesystem is to provide an easy way to view kernel and information about currently running processes.

If you build Linux from scratch, you will have to write your own /etc/fstab file.

/etc/mtab

This file handles the mounted devices and is automatically updated by the mount command.
And it looks a bit similar to fstab but not the  same ( notice rw and ro for read/write and read only ) and it does only lists the mounted devices !



 

To remove a swap file:
1 – At a shell prompt as root, execute the following command to disable the swap file (where /mnt/swapfile01 is the swap file):

2 – Remove its entry from the /etc/fstab file.

3 – Remove the actual file:

 

This is task that you will do many times when working with Linux/UNIX. This can be automated or done just as a simple one time task.

Best tool for this job is tar 

  • GNU tar  saves many files together into a single tape or disk archive, and can
    restore individual files from the archive.

GNU tar comes with many options but for my task i will use the following options only:

  • this command will create gziped archive containing the entire content of the www/ folder called www_aodba_bkp.tar.gz.

Options  used and their purpose:

  • -z Compress archive using the gzip program
  • -c  Create archive
  • -v  Verbose i.e display progress while creating archive
  • -f  Archive File name

To extract the content of a tar archive use the following command:

  • -C Extract location
  • -x Extract the content

  • this will extract to the current working directory.

  • this will extract the content into /folder directory.

 

GNU tar come very handy to be used on a daily basis by any system admin.

Hops this was helpful

In this article we will see how we can start an AWS EC2 instance for a non-stop state of Initializing.

Causes for this type of EC2 instance behavior are listed at this link EC2 tourbleshooting and  came well detailed by AWS documentation.

But in some cases like mine there is no official troubleshoot done.

So here is what i got in my System Log.

 

  • to get your EC2 system log you select it from the EC2 instance option list.

system_log

 

And here is the content of the log, just the part we are interested in:

What could’ve happened ?

  • it looks like the volume xvde has some problems. And this affects the entire host.

How can i fix this ? 

  • the host is not reachable !
  • i cannot edit the /etc/fstab file and remove the xvde entry !

Solution

 1 – Start a new instance.

2 – Detach the root volume (/dev/sda )from the bad host

  • the root volume holds the /etc/fstab file.

detach

 

3 – Attach the detached volume to the instance we started at step 1.

  • choose instance form drop down list.
  • choose the volume name as /dev/sdx  (easy to spot)

attach

 

 

4 – Login to your new instance and list the volumes attached to the instance using the lsblk command.

  • you don`t need to format the disk, this will erase the data.

5 – Create a mount point and mount the attached volume.

  • the /dev/xvdx2 volume content are reachable to you now to edit.
  • edit the /etc/fstab file and remove the entry with the failed disk.

Save the changes to the /etc/fstab file.

6 – Un-mount the /dev/xvdx2 volume and detach it from the new instance.

7 – Reattach the volume back to your failing instance.

Note:

  • you have to attach the volume as /dev/xvda.

8 – Start your failing instance and see the System Logs.

  • your host should up and running.

Also you will need to see what went wrong with the failed disk, in my case this was due to the fact i was using EC2 instance storage for a mount point. Lucky me this was only for temp space :).

 

In this short article we will go over the fix for this warning message “WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!”

Here is the output for this type of warning:

 Why do you get this error ? 

This is common when you change the name of your server or like in my case when you recover a server from a faliure and give it the same ip address as in the past.

 

What is the fix for this warning ? 

The fix is quite simple. You just need to remove the line from you ../known_hosts file that points to the ip/host you are trying to connect to.

1 – You can do by editing your known_hosts using and editor.

2 – Use ssh-keygen command with the -R option.

  • the -R option will require the host name or the ip address as input and it will remove the specific line from your ../known_hosts.

 

Next you just need to login again and the new key will be added to the ../known_hosts file.

 

And we are done !

Git

Git is a widely-used source code management system for software development. Version control systems like Git allow you to keep track of your software at the source level. You can track changes, revert to previous stages, and branch off from the base code to create alternative versions of files and directories.

To be able to install Git you need to have the sudo privilege.

We will use yum package manager, to search for and install the latest git package available.

to check the installed version run the following command:

Next step is to setup the Git.

  • i assume you already have a GitHub account created. If not go ahead and create one at GitHub.

To configure the Git account on your linux box ou will need to use the git command with the option config.

Check that the configuration have been saved by running the following command:

Now Git is installed and ready to use.

 

This is a step by step installation of Perl 5.16 on Linux CentOS 6.

Note:

  • run command one by one so you can spot any possible errors.

Step to complete this task 

  • all the command bellow must be done as the root user.
    Untar the perl ball

Move inside the perl folder

Install make and gcc if not already installed

Setup perl home

Start perl compilation

Remove old symbolic link

Create new symbolic link for the new perl install

Vertify perl version

Install pelrbrew

Install cpanm tool

Install perl modules

 

You have to love Linux ! There are things you can do in Linux that you don’t even dare to try in Windows :), don’t get me wrong my P.C. and my Laptop run on top of Windows but i spend most of the time logged on to a Putty terminal.

So. why this issue ?!

I am migrating some data out of SQL Server and i ma using the sqlcmd(much faster then using the GUI).

  • the problem is  that sqlcmd is quite limited when you try to export the data and apply a line terminator , apparently the -r option is not working.

  • so after exporting a table with 20 millions rows (about 12 Gb of data) i had to edit the file so i can add a semi-column a the end of each line. How do you do this in windows ? You don’t ! You might use NotePad++ but you Laptop will “crash” – windows cannot handle big files.:(

 So the solution is simple and is called Linux

I had to copy the exported file onto my Linux host and run a simple command on top if it.

  • so i just run a sed command specifying my line terminator string as ‘;’.

ohhhh another thing this was about 100 times faster done in linux then if i would do it in Notepad++ running on windows.

 

Recently i have setup a Vertica Cluster and faced some ssh connection laziness, for no reason my ssh connection took like 5 to 10 seconds to complete.
After some “debugging” online i have found a cool solution for the problem.
It is actually a parameter inside the /etc/ssh/sshd_config file called UseDNS, you just have to uncomment it and change it’s value from YES to NO.
After you edit the parameter restart your sshd server.

 

Apparently this parameter is telling SSH not to look for the DNS servers each time a client connects.

This week i was configuration a HP Vertica cluster environment and i needed to alter the /etc/hosts file on all of the hosts/nodes so that they can know each other.

Normally i do it one by one or i use MobaxTerm where i can work on more Linux hosts in the same time running the same commands(example bellow)

MobaxTerm

MobaxTerm Multiple Window Work

  MobaxTerm is my favorite remote terminal but still i want to make this appending process more automatic.

So let’s see how can we append a line/some lines to a remote file in Linux:

Base syntax :

 Example:

-we will append a line to a file, and then we read from the file.

So this is easy to implement in a script when you plan to build/add new host to HP Vertica Cluster(in my case).

I hope this was helpful.

scp remote

The scp command allows you to copy files over ssh connections. This is very useful if you want to transport files between computers. The scp command uses the ssh command to authenticate.
Some times you are not able to do scp from host A to host B for example but you can do scp from B copying data from host A.

The basic syntax is like this:
When you are login HostA and you copy files to HostB

But what if this is not possible and you get some error or the server is on different network or what ever..
Well in this case we will need to copy from the remote HostA to the local HostB

Copy remote file to localhost from localhost.

You also can use the -r option(recursive/copy all files) and allso the *(wildcard).

I am going to start by defining what is a Zombie Process

Well a Zombie Process is the actually the state of the process when the child dies before the parent process. In this case the structural information of the process is kept in the process table.
Danger !!!
Processes in Zombie State don’t use up any system resources. (Actually, each one uses a very tiny amount of system memory to store its process descriptor.) However, each zombie process retains its process ID (PID). If zombies are accumulating at a very quick rate the entire pool of available PIDs will eventually become assigned to zombie processes, preventing other processes from launching.
In any case, a few zombie processes hanging around are no problem – although they do indicate a bug with their parent process on your system.

How to remove or get rid of Zombie Processes ?
You can’t kill a Zombie Process the normal way as it does not exist.
One way is by sending the SIGCHLD signal to the parent process. This signal tells the parent process to execute the wait() system call and clean up its zombie children.
Example of the command:

How can you list your Zombie Processes ?

Normally you can see them by using the top command :
15_pic

 

But also we can

Example of the command: (ps aux | grep -w Zs)

In this post we are going see how can we change the host name of a Linux machine.
Just follow the steps below:

  • 1- Find and edit the following file “/etc/hosts”

  • 2- Edit /etc/sysconfig/network

Save and close the file.

  • 3- Type the following command:

Your new hostname should be set now.

In this article we will show you how to setup password-less login using ssh keys to connect to remote Linux servers without entering password. Using Password-less login with SSH keys will increase the trust between two Linux servers for easy file synchronization or transfer.
SSH Password-less login is one of the best way to automate tasks such as automatic backups with scripts, synchronization files using scp and remote command execution.

Let’s follow the steps in creating the password-less connection.

  • 1- First you need ot install SSH-client .
  • 2- Generate a pair of public keys.
  • To do so you need to use the commnads:(just press enter until the process finishes)

  • 3- Set directory permission
  • Next make sure you have correct permission on .ssh directory:

  • 4- Create the file authorized_keys inside .ssh folder and copy the content of the id_pub.pub inside of it.
  • This will hold the used keys for password-less connection.

  • 5- Change the permission on authorized_keys.
  • 6- Do the same on the other server where you want to connect password-less.
  • Just follow the first 5 steps.

  • 7- Copy public key from one server to another and place it inside the authorized_keys file.
  • Then try to connect to the server. You will be asked if you want to continue and the host will be added to to the known_hosts file.

    And that is it – ssh password-less is configured.

    With Sealinux enabled you may have problems starting the Oracle client library. This is because the SELinux feature does not allow the libnnz10.so Oracle library to be loaded.
    Be aware that by disabling SELinux you will be removing a security mechanism on your system.
    To work around this problem, you will need to disable SELinux on your system.

    To disable SELinux permanently, edit the file /etc/selinux/config and change “enforcing” to “disabled”.

    After editing the file save it and exit.