Friday, July 27, 2012

So close yet so far!

Today I took an exam for the LPIC-1 Linux certification exam, the first of two to complete the certification. I failed by a score less than 20 points from passing, which was much lower score than expected. It's annoying when you don't pass on two parts, first you technically (more on this later) lost the money you spent on the exam. Second, you feel like the time you spent studying was wasted since you didn't pass. But in reality, it's not exactly a lose/lose senario.

One of the method you prep for an exam is buying a book, then reading the book and focusing on the important details as mentioned by the author. Often times a certification book will focus more on passing the exam than actually getting knowledge of the subject the exam is testing. After this you may use the practice exam included in the book and once scoring high enough, will take the real exam. Hopfully passing the exam and on the way to the full certification.

But for some users, this doesn't work out so well. Books usually have limited space to discuss technical topics that dwell deeper than a few paragraphs. The narrow focus of just passing the exam often leaves more questions, now I know this command where would I use it? Not to mention that with the copy rights and agreements for the real exams, it's often difficult to find practice exams that are close to or near the real thing. Often you will pass the practice exam but find out the real exam is different.

So what is the best solution? It's really depending upon the person taking the exams and what they are used to. Personally I found the following to help me while studying.

Multiple sources for information 

I was using just one book for my LPIC-1 study program, and often found myself searching the Internet for a better explanation of the topic that was written in the book. One such topic was "suid" which is when an executable file is set to give the permissions of the owner when ran. The book I was reading explained how to set this up but not why or when it's used. Searching the Internet I found a great site that actually explained the subject in a much easier method to understand and even offered straight forward examples.


At home, I also have two other books on the subject of the LPIC-1 certification and while I try to use one book and then the Internet searching, I will consult with these books plus other Linux books. Reason being is that certification books typically want to focus on passing the exam (which is why I buy them) but it's difficult to explain a complex subject within a limited amount of pages. If you have any doubt about the subject, research it further!

Real exam vs practice exam

Something that is common with almost every exam book I read is the included practice exam CD. Typically this is a practice exam produced by a popular exam vendor such as Transcender or MeasureUP. Usually the exams are limited compared to the full practice exams from the vendor companies, meaning that they have a smaller question pool or offer less features.

The big issue I see here is really a strange problem between the test vendors and the practice test vendors. The vendors who write and issue the certifications do not want their certifications to loose value, so they often will have agreements with the test takers to not report any of their questions. This is to make the exams harder to pass and also stop brain dumps. But also how do you study for an exam test if you're not sure what will be asked? Isn't that the point of using a practice exam?

One of the best advices I heard is save your money from the practice exams and just take the real exam. Now this is not the cheapest method, especially considering that most exams can cost anywhere from $150 (Microsoft exams), $400 (Red Hat RCHSA exams), and even higher for some of the high end exams. But you do get to take the exam in the real setting, and see the actual questions. Even if you do fail, you still come away with the experience and also a grading chart showing what parts you missed and needed work.

Plus the big benefit, if you score highly you actually pass the exam not just pass a practice exam. The hardest part is spending the money multiple times if you are unsure of your skills for the exam. This is really off set by doing a self study program instead of paying for a video series (usually $500) or taking a certification boot camp ($3,500).

For now I'm still working on finishing the certification, but I feel much better that I saw so close the first time rather than just guessing how close I was using practice tests.

Monday, July 16, 2012

Preparing for an certification exam

The past two months I've been studying for the Linux+/LPIC-1 entry level Linux certification. The certification while entry level contains a large amount of details normally not used in daily operations, but still handy to know. So I went the typical route of buying the best rated book on Amazon, then going through the entire book chapter by chapter to study it. I feel the best way to study is writing down notes of the chapters, so I used Evernote from home and work.

After finishing the book, I continued on to the practice exams and found that I still didn't pick up most of the details from the book. I knew a large amount of details, improved my Linux knowledge overall, but the obscure details (font servers, etc.) were missed. I started to re-think my plan of studying, maybe I was going about this incorrectly?

I started to switch course and instead of using the book and going chapter by chapter, I checked out the actual guidelines for the exam. Here's LPIC-1 101 exam, which is one of two exams required for the certification. A nice feature of my book is that they include a PDF which following the exam and then gives you the chapter with page number where the topic is discussed. After switching to this method, I started to go down each section and take notes about the topic.

Since I was going straight to the answers, it was a much faster read and felt that I skipped over the unimportant (for the exam) topics. Also the big benefit is that I know for certain if I have a solid understanding of these topics, I can pretty much pass the test. But why and when would you want to read the book end to end?

If you need understanding how each component fits together, then I would recommend reading end to end. For example, if you're already using Linux or administration across other operating systems you know that troubleshooting often starts by reading the system logs. So you really don't need much back story as to why it's important to know the locations or using a search command (grep). For the newer users of Linux or someone fresh from school, they might not understand how important the logs are, then it would be good to read the entire chapter about logs and searching.

Also reading the book end to end allows you better understanding why you would need a search tool like grep then another tool like awk to help filter logs. A final good reason for reading the entire book is the examples and tutorials given in the book. Personally I feel that the tutorials help but the best method to learn is by figuring out yourself, which often leads to more research outside the book's text.

Something else to add, if you're preparing for an exam, use as many reliable sources of the information they you need. Currently I'm reading two books plus going over with two practice exams, and various information from the Internet. I'm pretty sure you could pass the test with just reading a single book but honestly it's a lot of information and there were questions left unanswered and just not possible to explain given the limited number of pages.


Sunday, July 08, 2012

O'reilly School of Technology review

Computer based teaching is a very to get just right. Sometimes you may presented with too little information while other times, it's too much and hard to follow. I found some of the online classes I taken in the past for work was a 30 page slide show with a short quiz at the end. By the time I was through the first chapter, I was dulled by the information given and lack of interaction. On the side, a class presented me with one or two paragraphs of text and then expecting me to complete an assignment with no outside information.

But computer based training that is based on-line has many benefits. The pricing of classes is usually cheaper than attending a physical classroom. Also the classes are available 24 hours a day, which works out great work people with changing work hours. Combined with the information you have available anywhere, the benefits are welcome for anyone.

Recently I took it upon myself to take a class with O'reilly School of Technology, which is part of the O'reilly book publishing company (the animal tech book publisher). The class I enrolled with is the first Linux/UNIX class for their System Administration certificate. The class focuses on the file system which includes user/group administration, cron jobs, hard and soft links, plus more. It's a general overview of the system, but not too in depth as there are three other classes (four classes are required to complete the certificate).

From the start, you work the entire classroom from a web page, which includes accessing the lab server and the lessons. This makes it very handy as you can access your class from any computer with a web browser. Here I tested mostly Google's Chrome on Windows and Mac which no problems. The lab access while handy, does cost an additional monthly fee but going with this during a normal pace you should be done within two months of light weekend work. On the side note, you can also complete the work without the lab but the work will be harder to present to the course instructor.

When you login to your virtual classroom, you are presented with the following as seen below. You have a file explorer on the left side. Followed by the class lessons and reading in the middle, then on the right is the reading page. Below is the console login for your lab host. The simple method of presenting information worked well but I did noticed from all networks that I connected to, there was a delay in working with the lab console. Also a big plus is the lack of any Adobe Flash on the site, a huge thanks!


The work is typically as follows. You are presented with a small chapter of information on a subject, which includes steps how you can do this in your lab console. Then you have a few assignments where you complete the work by either providing proof to the instructor (edit a file on X host) or by answering the question correctly. Then you are presented with a quiz, in a similar manner. It should be noted that none of these questions are multiple choice, and they are graded by a actual human. 

After you submit the homework and quiz, the turn around time for the corrections is about 24~48 hours, but I saw much faster times especially during the weekdays. If you're answers are correct, then you move on to the next step but if they are incorrect, the points where you are incorrect are marked and notes are provided why. It's important to note that the questions do not change as far as I know. This means that if you fail the question on the first time, when you return to answer the question, it's the same. 

The total amount of time to complete the class was about a month for myself, and that was taking my time, working on it as I wanted. For someone who was more focused, I'm sure this class could be done in a week, but I'm not sure just how fast the turn around for corrections could be completed.

The biggest question I had before attending this class is the pricing and what I would get from this. I personally dislike on-line classes, and I have taken classes from physical fitness, IT and math based subjects. All of them I felt lacked personal interaction and you mostly received generic answers and replies from the instructor. Also the lack of working with peers in the class also makes it more difficult to interact with other students for additional help or studying outside of the classroom. 

With the O'reilly school, I felt that it was a good amount of information and the interaction was much better. While the subject matter felt less than what I expected I did learn from the assignments and also it forced me to really think about my answer since it wasn't just answering a random multiple choice quiz at the end. The depth of knowledge required for this class was entry level into the world of Linux/UNIX and I feel like it was a slightly below my skill level but I still came away with some details I didn't know. 

Now if you are more focused on your own studying and can follow along in a book, this might not be the best value for you. You can find books and other learning materials available either free or for under $50 that offer much more information. But the big difference is that instead of working by yourself, you have someone to correct and assist in the labs with O'reilly. This doesn't sound like much but for some (especially myself) the contact with a instructor was extremely helpful. This also helps get you working harder and staying towards your goal since it's a live person you are working with, assigned to you. 

From my experience with this first class in the series, I am not sure I would continue with the other four classes. This is mostly based upon a few factors, one is the cost (at current pricing they are $400 per class plus lab time) and the other is subject matter. I'm currently focusing to complete my LPIC-1 certification this summer and the  classes offered by O'reilly while complete do not fully match the requirements of the exam. Also I want to further go into scripting and small amount of Python.

Personally I would recommend anyone who is interested in the O'reilly school to take advantage of the trial service which gives you limited access to the classes within seven days. If you don't like it, you can get a money back refund, but only if you do not go further than a set amount of lessons. Read the fine print before going too far in the class work as I heard it's something like 5 assignments (about two hours of work). 


Friday, June 08, 2012

Umask confusion

I've been studying for the LPI LPIC-1 test, which is a basic introduction to Linux certification. So far it's been a very interesting experience, really finding out so much more about the nuts and bolts of Linux. But there are some confusion I'm having, and find it best to write it out to solve the problem.

One confusion is with the Umask function and command. Here's a short summary on the subject.

In the Linux and UNIX system, new files and directories are created with a default permission. Keep in mind the following.

  • Read - 4
  • Write - 2
  • Execute - 1


  • Files - 666
    • Owner - Read, Write
    • Group - Read, Write
    • Other - Read, Write
  • Directories - 777
    • Owner - Read, Write, Execute
    • Group - Read, Write, Execute
    • Other - Read, Write, Execute
The owner is the user account who created the account, the group is the group associated with the file (most times it's the same as the user name), and the other is anyone who is authenticated on the system. 

Now the issue is that on a system shared by multiple users, these settings leave little to be secured. How can the Linux system have the files locked down but still allow others access? This is where the command umask comes in. Umask allows the system to follow a default setting of security across the system, sort of a lock down depending upon how secure you want it. 

Let's first find out what is the current umask setting. 
  1. From your command prompt, run the following command
    1. #umask
  2. You should see a value such as "0022"
For most Linux distributions, the default is 0022. Only the last three values are used, the first "0" is not used. For this detail the settings of umask are as follows. 
  • umask setting of "0022"
    • First "0" - Not used
    • Second "0" - Amount to remove from default settings of owner permission
    • Third "2" - Amount to remove from default settings of group permission
    • Fourth "2" - Amount to remove from default settings of other permission
Sounds confusing but here's how this is calculated. 
  • umask setting of "0022"
    • Files - default is 666
      • Owner - 666 - 0 = 666 
      • Group - 666 - 2 = 664
      • Other - 666 - 2 = 664
    • Directories - default is 777
      • Owner - 777 - 0 = 777
      • Group - 777 - 2 = 775
      • Other - 777 - 2 = 775
As you can see, the setting of "0022" (more commonly reported as 022 since we drop the first zero since it's not used) will remove permissions for Group and Other. This change is not so impacting but if we wanted we could make the system more secure by using higher amounts of umask. For example, 077 would give only the owner of the files the right to read, write and execute. 

Now that we know the basics of the umask command, how can we change this? There's really two methods, one is from the command umask.
  1. From your command prompt, run the following command
    1. #umask 0026
  2. Now create a directory and file
    1. #mkdir testdir
    2. #touch testfile
  3. Let's see if the permissions are different than before
    1. #ls -l
  4. You should see the following permissions
    1. Testdir - 751 (rwx-rx-x)
    2. Testfile - 640 (rw-r--)
But the change done by umask is not permanent, to do that you need to edit the /etc/profile. You can view the file and find out that there's actually two values given in the file (here we are using CentOS). Why are there two values in the file? 



The file script checks for the user account UID, and depending on the number, the user will either receive a umask of 002 or 022. Remember that service accounts are typically UID's under 200, while regular user accounts have UID's starting at 500 (typically). Also root has the UID of 1, so basically the system is giving a less enforced policy for more important accounts. 

To view the account UID, in two methods. 

  1. From the command prompt, run the following command
    1. #id -u useraccount
      1. Number returned will be your UID
    2. #cat /etc/passwd
      1. A full listing of all accounts on the system, showing UID
For more information about umask here are some very good links to read up on. 



Tuesday, June 05, 2012

Script to help with timing issues on virtual guests

There's an issue when running a virtual machine that the time gets incorrectly updated. The problem is that when you suspend the computer, the virtual machine will suspend and return with the incorrect time, instead of updating from the Internet. I have seen this issue more so on Linux than on Windows, but for Linux it's easily fixed by a simple script. Here's the basic steps to get it working.


  1. Open up Vi or your favorite editor on your virtual machine
  2. Type in the following details
    1. #!/bin/bash
      service ntpd stop
      sleep 5
      ntpdate pool.ntp.org
      sleep 5
      service ntpd start
  3. Save you file
  4. Change the permissions to all the file to be executable
    1. Run the following command
    2. #chmod 755 filename
  5. Test the command
    1. Run the following command
    2. #date
    3. You should see an incorrect time
    4. Run the script, note the "./" before the script name
    5. #./yourtimescriptname
    6. Run the following command
    7. #date
    8. You should see the correct time
  6. Now your virtual machine is updated
  7. You can add this script to a cron job or login script to automate the process
So far I just run this manually since I rarely reboot the virtual machine or login or out. You can make a symbolic link or an alias to make things easier to manage. 


Sunday, June 03, 2012

Adding a drive to VMware Workstation Linux guest without restarting

Recently I was working on a CentOS 6.2 guest on VMware Workstation 8 and I wanted to add an additional hard drive. From VMware Workstation I knew how to do this but not from the Linux side. Being unfamiliar with this, searched and found a few handy steps to add the drive without rebooting the Linux guest.

First, let's see what drives are showing up for the Linux guest. From the host we're going to check the /dev directory and see what drives are showing up.

#cd /dev
#ls





Here we can see that there is three drives, sda, sdb and sdc listed on the guest. Under these two drives is three partitions titled sda1 and sda2, plus sdb1. Notied that drive sdc does not have any partitions. This breaks down like this.

  • SDA
    • SDA1
    • SDA2
  • SDB
    • SDB1
  • SDC
    • No partitions
So now, we want to add an additional hard drive then add an partition.

From VMware Workstation, we're going to add the drive to the guest.

  1. Right click the guest, and click the "Settings"
  2. The Virtual Machine Settings window will open
  3. Click the "add" button
  4. The "Add Hardware Wizard" window will open
  5. Select "Hard Disk" then click the "Next" button
  6. Under the "Select a Disk" leave the default as "Create a new virtual disk", then click the "Next" button
  7. Under the "Select a Disk Type" leave the default as "SCSI", then click the "Next" button
  8. Under the "Specify Disk Capacity", change the value for "Maximum disk size (GB)" to the amount you want. For this example, I will be using 5GB. Then click the "Next" button
  9. Under the "Specify Disk File" leave the file name as default and then click the "Finish" button
  10. Back at the "Virtual Machine Settings" window, click the "OK" button to complete
  11. The new drive has been added to the guest
 If you check the guest again, you will notice that the new drive does not show up automatically under the /dev directory. There are two solutions to this, one is restarting the guest, the other is a little bit longer method. We're going to follow the second step, which is handy if you wish to keep the system up.

These commands were posted on another blog, Cyberciti's how to add a new VMware hard disk article.

First we're going to scan the system for the new drives. We need the host numbers on the guest machine first.

  1. First find the host number on your system
    1. Run the following command
    2. #ls /sys/class/scsi_host
    3. You should see the return of "host0" or more 
  2.  Force the system to scan the drives
    1. The host number you found in the previous step will be used here.
    2. Run the following command
    3. #echo "- - -" > /sys/class/scsi_host/host2/scan (note on my system it's "host2")
    4. After this you may see a message of the drive scanned on the machine
  3. To confirm, check the logs for messages of new drive
    1. Run the following command
    2. #tail /var/log/messages
    3.  This will be sequential from the last drives. For example, if you see in /dev drives SDA, SDB, then you should see logs for drive SDC
  4. From fdisk we're going to also validate it's showing up
    1. Run the following command
    2. #fdisk -l
    3. You should see the drive showing up that matches the drive from step 3
  5. From /dev you should also see the new drive listed
    1. Run the following command
    2. #ls /dev
    3. You should see the drive showing up that you just added
Now that we have the drive installed and viewed from the guest, let's create the partition and format. We are going to be using the steps as mentioned in the blog Cyberciti's how to add Linux hard disk.

  1. First find the drive has been discovered on the system
    1. Run the following command
    2. #fdisk -l | grep 'Disk'
    3. You should see the drive you added in the previous steps shown near the end of the list
    4. Save this information for the next steps. 
  2. Run fdisk to create the partition on the new disk (if anytime you get lost on commands, type "m" for the command menu
    1. Run the following command
    2. #fdisk /dev/sdd (your drive may be different)
      1. In fdisk, type "n" to create a new partition
      2. Type "p" for a primary partition
      3. Type "1" for a partition number
      4. Type "1" for a first cylinder number
      5. Type "1G" for size (this can be adjusted for your needs)
      6. Type "w" to write and save the information
      7. This will automatically close fdisk
  3. Validate the partition is now showing up in /dev directory
    1. Run the following command
    2. #ls /dev
    3. You should see the new partition showing up under the drive you just created
  4. We're now going to format the partition with ext3 so that it's usable 
    1. Run the following command 
    2.  #mkfs.ext3 /dev/sdd1
    3. You should see confirmation the command was successful
  5. Finally we are going to mount the drive
    1. Run the following commands
    2. #mkdir /disk1
    3. #mount /dev/sdd1 /disk1 (your drive may be different)
  6. Confirm the drive is showing up
    1. Run the following command
    2. #df -H
    3. You should see your new drive mounted
  7. Test the new mount
    1. Run the following commands
    2. #touch  /disk1/testfile
    3. #ls /disk1
    4. You should see your file written to the new mount
  8. Now set the mount at boot
    1. Run the following command
    2. #vi /etc/fstab
    3. Add the following line to the fstab file (note, I'm not going to show basic Vi commands here, you can find them across the Internet)
    4. /dev/sdd1         /disk1      ext3     defaults    1    2
    5. Save the file
  9. Done!
Now you should have a new drive on your virtual machine without restarting the guest. If you don't mind restarting then you can skip steps scanning steps. Also be careful of editing the /etc/fstab file, this can lead to problems with the boot of the machine.












Sunday, December 04, 2011

Install HTOP on FreeBSD

Working with command line I really miss some of the nice graphics you find with Windows based tools. The current Windows Resource Monitor included in Windows 7 and Windows Server 2008 is really my favorite. It's great to use for monitoring as it's a real time graph of the system performance. I know that Linux/UNIX tools like TOP can do the same but it's just visually easier to view a graph than numbers.

I recently started to use HTOP which is a more graphical version of TOP but is not as popular. The downside is that while it's more handy, you may need to have it installed manually, it's typically not included by default. Below is a screenshot of HTOP running.


Installing HTOP in CentOS is extremely simple.

#yum install htop

Done! For Debian based systems, use the following command.

$sudo apt-get install htop

Simple and easy, now run htop. But what if you want to install htop for FreeBSD? That's going to take a little bit more work.

Good news is that HTOP is available from the FreeBSD ports collection. This will make the process much easier that installing from source.

http://www.freebsd.org/cgi/cvsweb.cgi/ports/sysutils/htop/

For the actual installing, I following a few blogs and forum postings. One from The Technical Crib pointed me how to install the Linux emulators for FreeBSD. But after following the steps I received another error during the install process, which was covered in this FreeBSD forum posting. Finally, as suggested in the previous link, the fix was to install the source, found how to do that in this Cyberciti blog posting.

Below I will write out the full steps that worked for me, didn't discover this but it's complied between all the articles I found.

Installing the requirements 

1) Su or login as root

2) Run the command to enable Linux binarary compatibility for FreeBSD.

#kldload linux

3) Add to the startup

Edit /etc/rc.conf

Add following line

linux_enable="YES"

4) Install Linux base port f10.

#cd /usr/ports/emulators/linux_base-f10


#make install clean

5) Add linproc to fstab

Edit /etc/fstab

Add following line

linproc /compat/linux/proc   linprocfs   rw   0  0

6) Install Htop from the port

#cd /usr/ports/sysutils/htop

#make install clean

7) Htop should run!

$htop

Possible extra step

*note - htop should complete the install with no problems. If you see an error as the following, you may need to install the source files to your computer.

Error result ***


===>  Configuring for lsof-4.84A,5
Creating ./lockf_owner.h from /usr/src/sys/kern/kern_lockf.c
FATAL ERROR: can't read /usr/src/sys/kern/kern_lockf.c
FATAL ERROR: ./lockf_owner.h creation failed (see 00FAQ)
===>  Script "Configure" failed unexpectedly.
Please report the problem to ler@lerctr.org [maintainer] and attach the
"/usr/ports/sysutils/lsof/work/lsof_4.84A.freebsd/config.log" including the
output of the failure of your make command. Also, it might be a good idea to
provide an overview of all packages installed on your system (e.g. an `ls
/var/db/pkg`).
*** Error code 1


Stop in /usr/ports/sysutils/lsof.
*** Error code 1


Stop in /usr/ports/sysutils/htop.
*** Error code 1


Stop in /usr/ports/sysutils/htop.


Error result ***

I am using FreeBSD version 8.2 stable and saw this error, so I followed one of the links posted and installed the kernel source code. We're going to run through some settings with FreeBSD's sysinstaller, it's kinda of confusing but take your time and carefully tab around.

1) Su as root

2) Run the sysinstaller

#sysinstall

3) Select "Options", then tab to the "Select" button, press enter



4) Under the Options Editor, use the arrow keys to scroll down to "Release Name" value, we are going to change this by removing the "-p3" after "RELEASE". Press the space bar to open an edit window.


5) In the edit window, remove the "-P3" value. This is done because when we download the source files, it does not know where to find this source. Tab to "Ok" when done. Then press "q" to quit to the main screen.


6) Back at the main sysinstaller screen we are going to select "Configure", then tab to "Select" and press enter.


7) Use the arrow keys to select "Distributions" then then use the space bar to select to continue.


8) On the next page, scroll down again using the arrow keys and select "SRC - Sources for everything". Press the space bar to select.


9) Under the sub-components, you will need to select two source trees, Base and Sys. Scroll down again using the arrow keys and select the following with the space bar.

"Base - top-level files in /usr /src"
"Sys - /usr/src/sys (FreeBSD kernel)"

Tab to the "Ok" button again.


10) After this you will be prompted where to install the files from (CD/DVD/FTP, etc.). Since this is a smaller download, I would suggest FTP, and first starting with the main FTP site. Now if the FTP fails with the following error message

Warning: Can't find the '8.2-RELEASE-P3' distribution on this FTP server

Go back to step 5 and make sure you edited the name. 

Htop should finally run as normal! Yes, this was a pain but considering it's running a Linux based tool, wasn't that bad!

Rob

Wednesday, November 30, 2011

Alias, making quick custom commands

Recently I placed my home computer on the Internet for a remote access but also to run a personal web page. The problem I had is while I enabled ssh access using only private keys, I was still worried that I might leave a loop hole open on the system.

So here I was constantly checking the logs for any alerts to SSHD service. The command I would run is something simple, "tail /var/log/messages | grep sshd".

The results would typically something as simple as a few lines but it would be important to keep up on. Here's an example.



$ tail /var/log/messages | grep sshd
Nov 25 03:13:59 server1 sshd[927]: error: PAM: authentication error for user from 192.168.1.100
Nov 25 03:14:06 server1 sshd[927]: error: PAM: authentication error for user from 192.168.1.100
Nov 25 05:50:25 server1 sshd[1299]: error: PAM: authentication error for illegal user root from 192.168.1.100


Now this is kinda of a long command to type out each time, I was wondering if I could just type something shorter?

Here's where the alias command comes into play. From your terminal, you can type "alias" and find out what are your current alias commands. 

$ alias
g='egrep -i'
h='fc -l'
j=jobs
l='ls -l'
ll='ls -laFo'
m=more

We're now going to add our search command as listed above, but make an alias to "searchsshd". 

$ alias searchsshd='tail /var/log/messages | grep sshd'

Now, when we type "searchsshd" we get the following. 

$ tail /var/log/messages | grep sshd
Nov 25 03:13:59 server1 sshd[927]: error: PAM: authentication error for user from 192.168.1.100
Nov 25 03:14:06 server1 sshd[927]: error: PAM: authentication error for user from 192.168.1.100
Nov 25 05:50:25 server1 sshd[1299]: error: PAM: authentication error for illegal user root from 192.168.1.100

Pretty cool! 

Rob






Hard links vs Symbolic links

Working with Linux and UNIX offers some handy extras not typically found on Windows based systems. One great feature is hard and soft links, which is somewhat like a shortcut that you can create but looks just like a normal file.

This works great when you need to share a file but do not want to give permissions to the file directly. So how does this work? Every file on a Linux or UNIX based system is mapped to an inode. Inodes are the identification of every single file and object on the system. This includes users, files, rights, etc.

To see the inode values, you can run the command "ls -i".


rob@robmint ~/sandbox $ ls -li
total 4
2098382 -rw-r--r-- 1 rob rob 5 2011-11-30 17:29 testfile

The file "testfile" has a inode value of "2098382".

Now there are two different links we can create. One is a hard link, the other is a soft link. Here's the difference.

Hard link - These are files associated to the same inode. They are duplicate files and are independent from the original file. Also as you can see below, look the same but there is a slight hint.

Let's first create the hard link using the "ln" command.


rob@robmint ~/sandbox $ ln testfile testfilehardlink

Now let's see what we created. 



rob@robmint ~/sandbox $ ls -li
total 8
2098382 -rw-r--r-- 2 rob rob 5 2011-11-30 17:29 testfile
2098382 -rw-r--r-- 2 rob rob 5 2011-11-30 17:29 testfilehardlink

Again, we see the inode information is the same, but also note the value of "2". Which tells us that the original file "testfile" is linked two times, once to "testfile" and another to "testfilehardlink". 


So we mentioned that hard links are duplicates of the original file, but what happens when we delete the original file? Let's find out. We will delete the file "testfile" and leave behind "testfilehardlink".


rob@robmint ~/sandbox $ rm testfile
rob@robmint ~/sandbox $ ls -li
total 8
2098382 -rw-r--r-- 1 rob rob  5 2011-11-30 17:29 testfilehardlink

Now let's see if we can access "testfilehardlink". 

rob@robmint ~/sandbox $ cat testfilehardlink
1234

It works! Now, even after deleting the original, you can still access the data. But this looses the benefit of using link since now the file is no longer being updated from the original file. 

So now we know hard links, what about soft links? Let's create the soft links using the "ln -s" command. 

rob@robmint / $ ln -s testfile2 testfilesoftlink

Now let's look at the soft link we created. Notice how there is a visual reminder that it's a soft link. 

rob@robmint ~/sandbox $ ls -li
total 8
2097736 -rw-r--r-- 1 rob rob 10 2011-11-30 17:41 testfile2
2098382 -rw-r--r-- 1 rob rob  5 2011-11-30 17:29 testfilehardlink
2098638 lrwxrwxrwx 1 rob rob  9 2011-11-30 17:48 testfilesoftlink -> testfile2

Here we created the the soft link, but let's see how this works if we delete the original file. 

rob@robmint ~/sandbox $ rm testfile2
rob@robmint ~/sandbox $ ls -li
total 8
2098383 -rw-r--r-- 2 rob rob 5 2011-11-30 17:50 testfile
2098383 -rw-r--r-- 2 rob rob 5 2011-11-30 17:50 testfilehardlink
2098638 lrwxrwxrwx 1 rob rob 9 2011-11-30 17:48 testfilesoftlink -> testfile2


Now the original file is deleted, let's try to access the file "testfilesoftlink".


rob@robmint ~/sandbox $ cat testfilesoftlink
cat: testfilesoftlink: No such file or directory

As you can see, once the original file is gone, so it the soft link file. This is because the soft link is a link to the inode, not a duplicate file. 

Now, why would you want to use soft links over hard links? Soft links are a path back to the file, not to the inode, which means that you can access links across partitions. It's pretty cool feature and when working with longer path names this could be extremely handy. 

Rob








Friday, November 25, 2011

SSH access with keys and no password

One of the most handy things about SSH access is setting up the secure keys, allowing to bypass the password but keep a very secure access to the host. This allows a fast connection to the host, but also since you're using a security key, no one else will have access.

For a while I was having issues setting this up, I knew that you needed to create the keys but not sure how to setup ssh access further. So I setup a home server, using FreeBSD 8.2 at home and running a port forwarding from my home router. I wanted to keep this secure as possible, but also allow access from any location, so I could access my home system remotely. 

So here's the steps I used and hoping this will be helpful. 

First, if you're on a Windows system there might be some issues creating the keys. You can make keys from Putty but there is some differences, mostly you will need to rename the files and make some additional editing. In these examples I created the keys on a Ubuntu based system and accessing a FreeBSD host. Please note "user" is your account name and "hostname" is the machine name. 

Before starting, make sure you have your remote host setup if needed. Here I'm working on a home machine so I need to first edit the SSH service file located at /etc/ssh/sshd_config. I recommend using your favorite text editor, and will be listing only the important options below. 

First, make sure root SSH login is disabled, and only allowing your account to be listed. 


AllowUsers user


We are also going to disable password authentication. 

PasswordAuthentication no

Also allow RSA keys.

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

Save the file and restart sshd service. Now consider if you are accessing a company server the details will be different and these setup steps for the host might be already done. 

From your personal computer. 

1) Login to a host and access the terminal or console.
2) From you're home directory, run the following command.

user@hostname ~ $ ssh-keygen -t rsa

3) As seen below, you will be asked for the following details. You can take the defaults and press "enter" all the way through. If you would like added security, enter a passphrase when prompted. 

user@hostname ~ $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
[random letters and numbers] user@hostname
The key's randomart image is:
+--[ RSA 2048]----+
[random image]

4) Now check your directory and you should see the following files. The specific path is listed above as "/home/user/.ssh" directory. We are using the "a" option to view the .ssh directory since it is hidden. 

user@hostname ~ $ ls -la
drwx------  2 user  user       4096 2011-11-25 15:18 .ssh

5) So we have the directory there, now let's check for the files. We are going to change directory to .ssh and look for the files.

user@hostname ~/.ssh $ cd .ssh

6) We are looking for what files are in the directory. 

user@hostname ~/.ssh $ ls -l
total 20
drwx------  2 user user 4096 2011-11-25 15:18 .
drwxr-xr-x 57 user user 4096 2011-11-25 14:55 ..
-rw-------  1 user user 1675 2011-11-25 15:18 id_rsa
-rw-r--r--  1 user user  393 2011-11-25 15:18 id_rsa.pub
-rw-r--r--  1 user user  884 2011-11-25 15:01 known_hosts

7) We have two hosts that are important. id_rsa and id_rsa.pub, these are the two files which we created and will need to access remote hosts. 

id_rsa - This is your private key, you keep this on the computer that you are using to access other computers. This is a secure file not to be shared on remote systems but only on hosts you are using for clients. 

id_rsa.pub - This is the public key, you place this file on remote systems that you want to access remotely. 

8) Now we have the two files needed, we're going to copy the id_rsa.pub file to our remote system. This command will copy the files from your local id_rsa.pub to the remote host. 

user@hostname ~/.ssh $ cat id_rsa.pub | ssh user@192.168.1.1 'cat >> .ssh/authorized_keys'
Password:

There is a possibility this might fail. Make sure that under your home directory on the remote system you have .ssh directory and the file authorized_keys already created. If they are not there, then create them as needed. Below, run the commands from your home directory. 

user@hostname ~ $ mkdir .ssh

Now we are going to lock down the directory

user@hostname ~ $ chmod 700 .ssh

Now go inside the .ssh directory

user@hostname ~ $ cd .ssh

We are going to create a blank file to store the keys

user@hostname ~ $ touch authorized_keys

Again, we are going to lock this file down as well 

user@hostname ~ $ chmod 600 authorized_keys

Now try the command listed in step 8 again. This should work. 

9) Now try to ssh into the server again, you should not be prompted for the password and go straight to the terminal session. 

Hope this saves you time and keeps your system secure. 

Rob

Sunday, September 04, 2011

Windows Freeware applications list

The word free and Windows don't often go together. It's very common to find free open source applications in the Linux world but in Windows it's a bit harder to find, but they are there. 


Recently I found a few nice listing of free applications that are free or offer free trial versions. Really handy listing and some of the applications are just what you need for something small. 


So my personal list of free or open source applications for Windows is here. 


Filezilla - FTP client and server


Before I found Filezilla I was stuck using either the command line for FTP upload, Dreamweaver, or another paid FTP program. Granted FTP isn't something that requires a great deal of knowledge, but it just made things easier to use a mouse. Filezilla is basically everything you could want in an FTP client, I've been using it for years and never had any issues. 


AVG Free Client - Antivirus 


I have never compared anti-virus vendors but the interface of AVG is very simple and easy to use. AVG offers frequent updates and of course they ask that you upgrade to the paid version, which offers more options and protection. Personally it's a tie between AVG and other vendors that offer a free version but AVG seems cleaner.


Pidgin - IM and IRC client


There's many instant messenger clients and IRC clients out there but the interface of Pidgin is decently easy to use. The only issue is using some of the extra features that are included with the vendor's instant messenger client might not work 100% with Pidgin. For example Yahoo! Messenger conference does not appear to work correctly with Pidgin, but that's a minor issue. 


VLC - Media player


VLC is a handy media player that I often use over Windows Media Player. The best feature is this is a very universal player, can play pretty much any file you throw at it. 


FooBar2000 - Music player


My favorite music players have been Winamp and iTunes, but recently I have been using FooBar as it's lightweight and simple to look for files. There is many plugins available for FooBar and if you're looking for the simple music player interface this is highly recommended. 


CutePDF - Print to PDF


I have a love hate issue with Adobe's PDF format. I like how it's very simple to hold books but creating PDF's was an issue, if you didn't have the software there was little you could do. With CutePDF, you can print to PDF which is very handy and great for "recording" web pages or logging documents. I heavily use this for capturing e-mails or invoices that are in HTML format for archival.


Imgburn - CD DVD burner


Imgburn is very handy for create CD or DVD's plus creating ISO of physical media. The application is lightweight, offers a much simpler method than working with Nero. My only request is disabling the "successful" sound as it's annoying. 


TrueCrypt - Encryption 


TrueCrypt offers drive and directory encryption, plus ability to encrypt the hard drive upon bootup. Where this comes in handy is when you need to secure a directory from others, or when you need to have a laptop secured even if you loose it. It's also great to use for your USB memory sticks, and I highly recommend this be used since it locks down the file very securely. 


Notepad ++ - Text editor


Using Microsoft's Notepad is handy but doesn't offer correct formatting and other tools as does Notepad ++. I really like this application and even after buying a very expensive paid version of another text editor, still use Notepad ++.


Putty - SSH client


I honestly do not know of another SSH client for Windows that is free and highly used as is Putty. I just recently switched to using SecureCRT, a paid SSH client but only after I needed a feature not included with Putty. But I really liked Putty and used it for many years. 


Rich Copy - File copy utility


I've been using Microsoft's Robocopy and the add on TeraCopy but recently I found Rich Copy from Microsoft. I really like the interface of Rich Copy and the adjustments for the job which is handy for faster computers. It's also good for sync a directory or just auditing. 


For now these are my favorites and will add some more shortly. 


Rob

Searching for disk space on Linux UNIX

One of the most confusing issues I had moving to Linux was searching for large files. It's somewhat confusing on Windows but there are many graphical applications available to help with the process. On command line, it's a slightly different process but still similar steps taken. Here's an example of searching for the largest files on a host. 


First, run the command "df -h" 


-bash-4.2$ df -h
Filesystem              Size    Used   Avail Capacity  Mounted on
/dev/sda1              3.9G    927M    2.7G    25%    /
/dev/sda2               10G     10G      0G    99%    /home
-bash-4.2$ 


Now you know the largest files are in the /home directory. Run the command "cd /home" In the example below, there's only one user, "rob" so I will go straight to the path.



-bash-4.2$ cd home/rob
-bash-4.2$ sudo du -sh *
9.9G    logs
 17M    dev
4.0K    documents
 12K    tools
-bash-4.2$

We find that in the path /home/rob/logs there is 9.9G of files. One method is to move the files to another directory or you can move the files, compress them then move them back. Just a note, certain files that are already compressed (mp3, jpg, zip) will not compress that well. Others such as text and log files compress extremely well. 


For the same path /home/rob/logs we find there are many log files taking up the space. 




-bash-4.2$ ls -lh
total 5
-rw-r--r--  1 robertf  users   2.5G Aug 31 23:00 log_083111
-rw-r--r--  1 robertf  users   2.5G Sep  1 23:00 log_090111
-rw-r--r--  1 robertf  users   2.5G Sep  2 23:00 log_090211
-rw-r--r--  1 robertf  users   2.5G Sep  3 23:00 log_090311
-rw-r--r--  1 robertf  users     5M Sep  4 07:46 log_090411
-bash-4.2$ 

We do not have space on /home so let's copy to /tmp to run the archive command


First create the folder on your /tmp directory by running the command "mkdir /tmp/rob"

-bash-4.2$ mkdir /tmp/rob

Then let's move the files over using the command "mv * /tmp/rob"

-bash-4.2$ mv * /tmp/rob

Just make sure the files have been copied

-bash-4.2$ ls /tmp/rob
log_083111      log_090111      log_090211      log_090311      log_090411


Now, we can start the compress of the files using the command "tar -zcvf log.tar /tmp/rob"


-bash-4.2$ tar -zcvf log.tar /tmp/rob
tar: Removing leading '/' from member names
a tmp/robertf
a tmp/robertf/logs
a tmp/robertf/logs/log_090411
a tmp/robertf/logs/log_090311
a tmp/robertf/logs/log_090211
a tmp/robertf/logs/log_090111
a tmp/robertf/logs/log_083111

Let's check again if the tar file has been created. 


-bash-4.2$ ls
log.tar

Now, the log.tar was created in the original location /home/rob/logs so we don't need to move that back from the /tmp directory. 


This is just a small example of how to find and clear space on your system. There are many many other examples. 


Nixcraft - How to find large files

Rob












Thursday, August 04, 2011

New job

It's been a while since I updated this blog. For the past few months I've been busy with work, looking for a new job and finally starting a new job. I'm very excited to move away from the Windows world and work entirely with Linux and FreeBSD but it's also a big learning curve.

For now, I'll spend my time on the transition skills, things I know in Windows but not confident in Linux. Also I will be relearning networking skills as I haven't heavily used this knowledge in a long time since I was so OS focused.

How's that saying goes? Be careful what your wish for?

Rob

Tuesday, December 21, 2010

Camera Straps

Since as long as I can remember, I've used the standard camera straps for all of my cameras. Of course point and shoots would use the smaller wrist strap but the SLR cameras were all your basic neck strap with two points connecting to the camera body. About 5 years ago I swapped out using the factory straps for the Op-Tech Pro Strap which I really like. It's a neoprene material on the area where it would rest on your neck and offers more flex than traditional straps, which is handy with heavy cameras. It's also reasonably priced, and I have three of them across my cameras.

In the past few years the trend of different camera straps have been getting popular on the camera forums. From using a sling style strap, hand straps, and the body carriers have all gained a loyal following. As someone who has struggled carrying a should strap camera bag, then a tripod bag, and a camera with another strap, I've taken a look around what would be a better solution. I have not purchased any of the new styled straps but have some comments as I carry my gear in different methods to match my needs. As of now, I'm still using the same Op-Tech camera strap but considering a sling strap.

Keeping the camera close yet out of the way

One issue that I run into is how to secure my camera while also keeping it out of the way while walking or traveling. Sounds confusing but here's a common issue, I carry a shoulder bag which I wear on my left shoulder or across my body on the right shoulder. Then I have a tripod bag, usually carried in the same manner, then I want to have my camera at easy access, again on my neck. Sounds confusing and it is!

I started to take my tripod out less, and now using a beltpack for my gear instead of the standard shoulder bag. But I'm starting to carry my camera instead over the neck, but more like a messenger bag across my back. This method I like for various reasons but it's really easy to keep the camera out of our way, especially with a large lens, also it allows a secure hold of the camera while moving. I had the camera in this position during running or walking through crowds and never had a problem.

Also speaking of crowds, I like to hold the camera in this position because it's not swinging side to side as I walk. I feel it's a smaller profile, and like to keep one hand on my bag to make sure it's also not swinging side to side either. A large bag weighing near 15lbs isn't something to bump into people.

Why I like the standard strap?

As mentioned earlier, I haven't tried the sling straps yet, the prices are about $50~100 for a complete setup. One issue that I really like using the standard strap is two mounting points vs one. The tripod socket is pretty strong on most cameras, built into the camera frame but I'm not sure it's the best place to dangle a camera all day from. If you have been reading some of the forums about these sling straps there's also complaints that the tripod socket connection will work it's self loose, dropping the camera to the ground.

The problem I see here is with the two point strap like a standard camera strap, the body and lens have lens chance to twist around. Many of the sling strap lugs that connect to the tripod socket are fixed like a eyelet bolt, which does not allow free movement, so if the camera starts to spin clockwise, it's going to unscrew the mount. I have seen one brand that added a bearing system to their tripod mount, Sun-Sniper which I think is safer.

Not to mention that the camera, I think, has more secure points with the standard camera strap connections built on the camera body. Since there are two, it's less stress on the body and also as discussed, less twisting. One big plus I like about the standard camera strap is you can wear it either over the neck like a standard strap or over one shoulder like a messenger bag. Then it's more like the sling strap, giving you quick access to the camera but also out of the way.

The point which I think makes the standard camera strap also better is it's closer to the body. Now this is something personal, but I really don't like to have my camera swinging far from my body, especially with a large lens. Even if you're a working pro, the last thing you want is to loose a lens from bumping the corner of a desk while on assignment. I've seen some of the straps hang very low and loose, really asking to be banged up against anything.

Another point against  the sling style is users of quick release tripod camera mounts. Most tripods now use beveled edge mounts to mount the camera to the tripod head, usually these are metal plates mounted to the camera's tripod socket which are a bevel to hold the camera to the tripod head. There's no place to mount a sling style strap unless you remove the camera mount and replace it with the loop for the sling strap. I like to use my tripod when I'm out taking photos but this would require me to completely change my setup.

Hand straps?

There's some photographers who don't use a strap at all in the traditional sense. The strap of choice is a hand strap which I'm seriously considering. The sling and standard camera strap both support the camera while carrying it, but they don't offer any support while actually using the camera. During a long coverage for a wedding, I held my camera with flash unit, plus a heavy lens all day, after which I really wished for some hand support. I've been looking at the hand straps as they offer two positive points.

One is the added strap to hold the camera to your hand, instead of using your fingers for grip, you can relax your hand and the weight is now supported by the arm muscles. The other is it's out of the way, less straps to deal with and easier to pack in the camera bag. The slight downside is that you will need either a battery grip or attachment to mount the hand strap, also the biggest problem, no saftey strap incase you drop the camera.

I like to have my camera teathered to myself at all times, or on flat ground. I try to be very careful with my gear but of course mistakes and accidents happen, so I try to take all pre-cautions as possible. I would assume you could strap on a hand strap and camera strap to the same top mount but it would be very hard to have both straps through the same mounting point. A plus to the sling style straps as they use the tripod mounting point.

What is really the best strap?

Really depends on your photography style and needs. I really like to have a multipurpose strap and the standard camera strap does that well for me. I can carry it in the normal position, also I can carry it like a sling.  Also it's not in the way when I'm walking but can be right in front when needed. It's also great that I can use other attachments for the tripod socket as needed, like a quick release bracket or another attachment.

I think for now, I'm going to stick with the standard camera strap and maybe purchase a hand strap to save arm strength, this gives me the most options.

Wednesday, November 17, 2010

Finding a job by reversing the roles

In times when jobs are harder to find, you need to stay active on your resume and constantly check job postings to stay current. In the last few months, I've been reading mostly job boards, about a few times a week, looking for job roles that I match, checking the requirements, skills they request, and type of work. I also note if the company type, if it's a start-up, contract position, or contract to hire, including job title. 

It's really interesting and if you have read What Color is your Parachute? the best method to find a job is by working in reverse order. How does that work? First, you need to think about the need for the job? When there's a need for a new job position, often times it's requested by a hiring mananger, who then reports the opening to the HR department, then is posted on the Internet, which you might see and reply to. The problem is that you're applying for a job to the person who might have the least amount of knowledge for the job, then filters the contacts to the hiring manager.

Not to mention that you may be the perfect employee, but you need to filter past many hands and departments, it's more difficult than just having the right skills to get the interview. When thinking about this problem, I think about the other side, from the hiring manager's perspective.

For the hiring manager, they know what to look for and what they want in an employee. The skills required and the function this person may do in their role. But it's another thing to sort out the people with the actual skills versus the people who may over rate their skills on a resume, as anyone can add mention a technical phrase to a recruiter to get an interview. So now, the hiring manager will now need to filter out all of these resumes, and usually a long task of finding the right person.

The big problem I see of this is that there's a large communication problem between the two main parties, the person who wants a job and the hiring manager who wants to hire someone. With many parties in between, it's a common issue that while you may be the perfect person for the job, a person down the chain of the hiring process may have other ideas. It could be as simple as you are not experienced but still have the knowledge, or maybe you understand product X but they are looking for someone who knows product Y.

It's very confusing, and often times I think that the hardest part of finding a job is getting past the hr department, as their role is often not to hire someone but to filter out those who do not match the job perfectly. Not to say hr department is easy, trying to become an expert for many departments in a company and filtering out the correct people is an incredible difficult job.

I think keeping this in mind is a good thing to remember when writing a resume. Often you need to really show what you can do and remember that the resume is the first item a hiring manager will see of you. It's really hard to show myself based upon a piece of paper, but considering the amount of time people can spend on each resume, it's the best to be honest and place your skills clearly. Also remember to tune your resume for the job as your applying for.

This means that if you're applying for a job working with customer service, highlighting your customer service skills will be better than listing other skills (but those might be a close second). The idea before was that you would make one resume as a "one size fits all" approach but now it's a resume by job idea that I feel works best. In some cases, I had recruiters call me for one job role which I had skills for, and ask if I could do these tasks. Since I didn't list the skills by the actual name on the job description they were reading from, the recruiter asked me a few questions then told me I probably don't have the skills and wished me luck on my job search.

I recommend that if you're looking for a certain job role, make a resume especially suited for the job. Then if you have another secondary job role, make another resume for that. I think this is somewhat the idea in fishing, as one lure might work ok for catching fish in a large lake but having multiple lures will work even better as different fish might be attracted to different types of lures.

Rob