Linux Tech Hacks

Your Linux tech hacks and Tips

10 Tips To Write Expeditious Bash Scripts


10 Tips To Write Expeditious Bash Scripts
Bash is indeed one powerful tool, and here are some tips to make bash scripts more efficient!
Bash the command line interface for many Linux distros is one is one powerful tool. Here we bring to you 10 niche tips which will help you keep your Bash scripts efficient and lean.
  1. Avoid Full Paths to Bash Built-ins
    Bash has many built-ins that can be used instead of calling external commands. You should leverage the built-in commands whenever possible since it avoids calling a sub-command from the system.
    Since Bash has built-ins for some commands found in /bin and /usr/bin (such as echo), avoid using the full path for these commands and the built-in will be used.
    # avoid this
    /bin/echo "hello"

    Use the Bash built-in instead:
    echo "hello"
    Other bash built-ins include: test, read, declare, eval, let pushd and popd. You can refer the bash man page a full listing of built-ins.
  2. Avoid External Commands for Integer Math
    Bash also provides built-ins that can be used for integer arithmetic. Only use /usr/bin/bc if you need to do floating point arithmetic. Integer calculations can be made with these Bash built-ins:
    four=$(( 2 + 2 ))
    four=$[ 2 + 2 ]
    let four="2 + 2"

  3. Avoid using Cat
    Tools like Grep, Awk and Sed will take files as arguments. There is rarely a need to use /bin/cat. For instance, the following is unnecessary:
    # avoid this
    cat /etc/hosts | grep localhost

    Instead, use Grep's native ability to read files:
    grep localhost /etc/hosts
  4. Avoid Piping Grep to Awk
    If using Awk, you can often eliminate the need for grep. Try not to pipe Grep to Awk:
    # avoid this
    grep error /var/log/messages | awk '{ print $4 }'

    Use Awk's native ability to parse text and save yourself a command.
    awk '/error/ { print $4 }' /var/log/messages
  5. Avoid Piping Sed to Sed
    Sed can take more than one command in a single execution. Avoid piping sed to sed.
    # avoid this
    sed 's/hello/goodbye/g' filename | sed 's/monday/friday/g'

    Instead, use sed -e or delimit the sed expressions with a semicolon (;)
    sed -e 's/hello/goodbye/g' -e 's/monday/friday/g' filename
    sed -e 's/hello/goodbye/g; s/monday/friday/g' filename

  6. Use Double Brackets for Compound and Regex Tests
    The [ or test built-ins can be used to test expressions, but the [[ built-in operator additionally provides compound commands and regular expression matching.
    if [[ expression1 || expression2 ]]; then do_something; fi
    if [[ string =~ regex ]]; then do_something; fi

  7. Use Functions for Repetitive Tasks
    Break your script up into pieces and use functions to conduct repetitive tasks. Functions can be declared like so:
    function_name() {
      do_something
      return $?
    }

    Make your functions usable by more than one shell script by sourcing a functions file from the various scripts. You can source another file in Bash using the . built-in.
    #!/bin/bash
    . /path/to/shared_functions

    See the Bash man page.
  8. Use Arrays Instead of Multiple Variables
    Bash arrays are very powerful. Avoid using unnecessary variables:
    # avoid this
    color1='Blue'
    color2='Red'
    echo $color1
    echo $color2

    Instead, use Bash arrays.
    colors=('Blue' 'Red')
    echo ${colors[0]}
    echo ${colors[1]}
  9. Use /bin/mktemp to Create Temp Files
    Need a temporary file? Use /bin/mktemp to create temporary files or folders.
    tempfile=$(/bin/mktemp)
    tempdir=$(/bin/mktemp -d)

  10. Use /bin/egrep or /bin/sed for Regex Pattern Matching
    Think you need Perl? Check out Sed or Egrep (grep -e) for regex pattern matching.
    # grep for localhost or 127.0.0.1 in /etc/hosts
    egrep 'localhost|127\.0\.0\.1' /etc/hosts

    # print pattern localhost.* in /etc/hosts
    sed -n 's/localhost.*/&/p' /etc/hosts
Courtesy: hacktux
 Fonte: 10 Tips To Write Expeditious Bash Scripts

10 Command Line Tricks To Create A Random Password


10 Command Line Tricks To Create A Random Password

Here's time to have some fun with command lines and and create a password that no one can hack (hopefully)!


One amazing part about Linux is that it allows you to do one thing in hundreds of different ways, even if it is something as simple as generating a random password. Here's 10 ways you can do it.

All of these random password commands can be modified to achieve a different password length, or simply use the first x characters of the generated password if you don't want such a long password. We suggest you to use password managers like LastPass so that you don't need to memorize them.

1. This method uses SHA to hash the date, runs through base64, and then outputs the top 32 characters.

date +%s | sha256sum | base64 | head -c 32 ; echo
2. This method used the built-in /dev/urandom feature, and filters out only characters that you would normally use in a password. Then it outputs the top 32.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
3. This one uses openssl's rand function, in case this is not installed on your system don't worry, we have a lots of other examples!

openssl rand -base64 32
4. This one works a lot like the other urandom one, but just does the work in reverse. Bash is indeed super powerful!

tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
5. This example filters using the strings command, which outputs printable strings from a file, which in this case is the urandom feature.

strings /dev/urandom | grep -o ':alnum:' | head -n 30 | tr -d '\n'; echo
6. An even simpler version of the urandom one.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
7. This one manages to use the very useful dd command.

dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
8. You can even create a random left-hand password, which would let you type your password with one hand.
< /dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""




9. If you're going to be using this all the time, it's probably a better idea to put it into a function. In this case, once you run the command once, you'll be able to use randpw anytime you want to generate a random password. You'd probably want to put this into your ~/.bashrc file.
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
You can use this same syntax to make any of these into a function - just replace everything inside the { }
10. not as random as some of the other options, but honestly, it's random enough if you're going to be using the whole thing. And yes, that's much more easy to remember.
date | md5sum
Courtesy: howtogeek


 Fonte: 10 Command Line Tricks To Create A Random Password

7 Most Surprising Places You Will Find Linux!

Did you know that Linux milks cows, runs a motorcycle and makes coffee too?

Linux, open source, strange linux, unexpected linux, linux surprise, Linux motorcycle, Linux Robots, Linux in US Postal Service, Linux Coffee maker, Linux milks the cow, Linux Security Cameras, Linux traffic lights


Thursday, October 17, 2013:  Open source and specifically Linux isn't all about license or a coding methodology, it has already begun to sprout up everywhere apart from just your computer systems and applications. Here's a compilation of some of the more surprising places you'll find your beloved operating system. 

1. US Postal Service

Linux has gone postal. For the past decade, the US Postal Service has relied on a mail sorting system that uses Linux OS at its heart. And for those who really love Linux, there are some Linux themes stamps to decorate their mail which can be found at Zazzle.com.

2. Robots

Isamu is said to be the first humanoid Robot to run on Linux late in 2001. But since then, Linux has become a popular basis for all kinds of robots including Pleo, an animatronic dinosaur toy and the Katana Robotic Arm for industrial applications built by Neuronics.

3. The Linux motorcycle

Mavizen's TTX02 is billed as the first electronic racing motorcycle with an onboard-computer, USB ports and an IP address. This lets the crew tune the bike over a WLAN. It can hit speeds of 130 mph and it's all powered by a Linux system.

4. Coffee maker

This commercial coffee maker was on display at Embedded World in Nurmberg, Germany. It runs on Linux and was built with the Qt framework. It's not available for consumers, but a few years ago a Linux lover published instructions for building your own Linux coffee pot. We say cheers to Penguin-inspired Java.

5. Linux milks the cow

Farm equipment manufacturer, DeLaval made a robotic milking machine that not only runs on Linux (and Windows), but lets the farmer operate it via a wireless, remote control. Now that's what we call milking a free OS.

6. Security Cameras

Linux backs the Zone Minder's home video camera surveillance system. ZoneMinder is an integrated set of applications for surveillance, capture, recording of any CCTV or security camera attached to a Linux-based machine. There is no limit to the number of cameras the app can support, beyond what your Linux machine can handle.

7. Traffic Lights

Next time you're stopped at a traffic light, take a moment to think geek...or rather Peek. Peek Traffic makes a series of Linux-based traffic lights that keeps traffic flowing in places like Iowa, New York and on the 101 in L.A.

Courtesy: CIO 

Fonte: 7 Most Surprising Places You Will Find Linux!

10 Awesome Linux Speed Hacks


Linux, open source, Linux hack, 10 linux hacks, linux hacking, top 10 linux hacks, linux speed hack,







Speed up your Linux machine with these awesome hacks!


Monday, October 07, 2013 Although Linux, the brainchild of Linus Torvalds is an extremely reliable operating system, and rarely needs to be rebooted, but when it does, the speed is a major concern. With Matrix style lines scrolling down the screen, it can make many lose patience. But fortunately, there are ways to speed things up. A majority of these tips are not very tricky all though some of these are unfortunately. Let’s take a look at top 10 speed hacks of Linux and let your Linux box reincarnate with speed.

1. Quick Fixes - Disable unnecessary services to make Linux boot faster

Linux comes in various flavors bundled with a lot of applications. However, most of us don't even use Linux to its full potential. Depending upon the use of the machine, plenty of services and running programs won’t be needed. And if you are using Linux just for a desktop, then you won’t be needing the default send mail, httpd, and many other services. You can also turn off many other services if your Linux box is used as a small web server by going to Administration menu, tweaking the Services entry and deselect all of the services you don’t want to start.

2. Free up Your Kernel - Disable unnecessary kernel modules

If your Linux box is wired to the LAN/Ethernet, then you don’t need to have a wireless kernel module loaded. More services like smartcard modules and others can be disabled and the load can be taken off from the kernel. This task is a bit difficult as it requires recompilation of kernel, which is daunting for even the Linux geeks. To do this, you will need the kernel sources and then follow the standard steps for compiling a kernel. You will be having a ride through the internals of your system just disable all of the kernel modules you don’t need.

For added safety, install Bootchart which will tell you if Kernel modules are properly installed and running on your system. Not only will this give you a good list of modules, it will illustrate for you what is happening during your system boot. You can also issue the command

chkconfig –list | grep 3:on

to find out what services are running. Once you know what loading modules you don’t need, you can remove them during a kernel recompilation. While you’re at it, compile the kernel to exactly match your architecture.

3. Take Load Off Linux - Use a lightweight window manager instead of GNOME or KDE

Using a smaller window manager drastically reduces graphical boot time. Instead of having to wait that extra 30 to 60 seconds for GNOME or KDE to boot up, why not wait two to 10 seconds for Enlightenment or XFCE to boot up? Not only will they save you boot time, they will save your memory and the headache of dealing with bloatware.

4. CUI ROKZ’ - Use a text-based login instead of a graphical login

The graphical logins do two things: increase load times and create headaches trying to recover from an X windows failure. Most of Linux machines which boot to run level 3 instead of run level 5 will halt at the text-based login, where you only have to log in and issue startx to start your desktop of choice. So CUI login is the way to go.

5. The Flying Penguin - Use a lighter Linux distribution

Are You a Linux newbie? Instead of loading the heavyweight SUSE, why not try a DSL, Puppy Linux, or Gentoo? The boot time is less than the more bloated Fedora (SUSE and even Ubuntu). Loading lighter Linux distributions will save you from lot of headaches. Of the larger distributions, OpenSuSE claims to boot the fastest, but between the latest Fedora and Ubuntu, Ubuntu blows Fedora’s boot times away.

6. Get Savvy - Use an OpenBIOS

If you’re tech savvy enough to upgrade your PC’s firmware, you might consider migration to open source BIOS which will allow Linux to actually initialize the hardware as it boots (instead of relying on the BIOS). Also, many open BIOSes can be customised to meet your machine’s specific needs. If you don’t go the open BIOS route, you can at least configure your BIOS to not search for a floppy drive that’s not there or to boot directly to the first hard drive (instead of the CD drive first).

7. DHCP woes - Avoid dhcp

If you are working on a home network (or a small business network) where address lease isn’t a problem, go with static IP addresses. This will keep your machine from having to call out to a dhcp server to get an IP address. If you take this approach, make sure you configure your

/etc/resolve.conf

to reflect your DNS server addresses as well.

8. Hotplug unplugged - If you can spare it, get rid of hotplug

Hotplug is the system that allows you to plug in new devices and use them immediately. If you know your server won’t need this system, delete it. This will cut down on boot time. On many systems, hotplugging consumes much of the boot time. Removing hotplug will vary depending upon the distribution you use.

Although udev has majorly replaced hotplug. But if you’re running an older distribution, this does apply.

9. Initng for the daring ones

The initng system serves as a replacement for the sysvinit system and promises to drastically decrease boot times in UNIX-like operating systems. If you would like to see the initng system in action, you can give the Pingwinek livecd a try.

10. HackerPunk - Use a hack with Debian

If you’re using Debian, there is a simple hack you can use to switch your startup scripts to run in parallel. If you look at the

/etc/init.d/rc

script, you will see:

CONCURRENCY=none

around line 24. Change this line to

CONCURRENCY=shell

and you should see a reduction in boot times.

Courtesy: theprohack


10 Awesome Linux Speed Hacks

Busting The Biggest Myths About Linux!


Here we are killing the 8 biggest fears that non Linux users have before they switch their OS! 

Linux, Open Source, linux myths, linux facts, linux kernel, Linux OS, Linux games, linux and windows, windows 

Tuesday, October 08, 2013 For many years Windows was the only operating system for many computer users. In fact, a majority of these users even didn't know that there was any other OS in the world. And for this reason, Linux, the free and open-source operating system was totally alienated. And slowly when people started to hear about the Linux based OS, many misconceptions started to cloud the free flow of the free and open source OS. So here we are trying to put some light on the real facts by killing the popular misconceptions! 

1. Misconception: Linux is an Operating System (OS)

Actually it is not. Linux is an OS kernel. The kernel is the core of all operating systems, and of course Windows has one too. The quality of the kernel is vital to the running of the OS. If your kernel is slow or buggy, your entire operating system will be slow and buggy. This means more crashes, freezes and hence data loss.

The proper name for an operating system using the Linux kernel would be “GNU/Linux”, because the Linux kernel wouldn’t do much for you without the GNU project software. Although for the sake of readability of this list “Linux” has been used instead of “GNU/Linux” while referring to the operating systems that use the Linux kernel.

2. Misconception: Linux is a command line OS

Well, while command line does makes Linux strong, but it isn't necessary to use them. Different desktop environments like KDE and Gnome looks some what similar to Windows and are a good choice for those who want a break from Windows look and feel. Their are many other choices like Enlightenment, Metacity, IceWM, Blackbox, Window Maker, FVWM etc.

3. Misconception: Linux is for geeks only

Although this was true years ago, as Linux was an infant but it certainly isn’t like that any longer. If you take a careful look at the user interfaces of Linux and Windows, your find Linux much more intuitive than Windows.

4. Misconception: Linux is not compatible with Windows stuff

No to a big extent and yes to a very small extent. For majority of the users, Linux is very much compatible. One can read your emails, open your Office documents, view and edit your photo albums, and do everything that you do on your Windows PC- in fact often with better and faster tools than you’d be able to find on Windows. Flagships of open-source software like The Gimp, Inkscape, OpenOffice and many others, can import, read and often export proprietary file formats like Microsoft Office documents, Photoshop PSDs etc. And these tools can offer you even more than you’re used to. Like your OpenOffice docs can be exported from my document to PDF in just one click. No custom printers installed, no “free” web converters. It’s all natively supported.

Although, a few files can’t be directly opened here but it's not Linux who has to be blamed here. Put your blame to the author software of these files. Would you really want to depend on your software vendors to be able to access your data or would rather use an open-source and standardized format?

And if that does not sound good enough, Linux comes with a Windows translation layer called Wine. Using this layer you can run Windows application on Linux. Basically, it serves as a bridge between Linux and Windows applications. For you that means not giving up your familiar Windows programs.

5. Misconception: Nobody is using Linux

Well, this is one very very wrong concept. Infact a majority of the World Wide Web is standing on the shoulders of Linux and GNU software. Because Linux is modular and secure, it’s the most logical choice for a web server. Not only that, many corporate to tech companies and governments have switched their systems to Linux. It’s cheap, durable and safe. Unlike commercial operating systems, it is maintained by the community.

6. Misconception: Linux doesn’t have technical support

It definitely does, and one can choose between paid and unpaid technical support. Unpaid technical support means that you have to depend on the large number of communities based online, where guidance is available twenty four hours a day. These are basically community of enthusiasts, who love to use and promote Linux and will be more than willing to help you with your problem.

As far as paid technical support goes, there are companies such as Red Hat and Canonical which do just that.

7. Misconception: There are no games for Linux

Well, yes once upon a time, games were a major drawback. This is especially true in terms of volume and we agree that there are a lot more games for Windows than for Linux but the scenario has definitely improved as compared to the past and almost every company today has decided to make a Linux version of their game. Linux now has its own version of all big games like Doom, Quake, Heroes of Might and Magic 3, Civilization 3, Soldier of Fortune, Tribes 2 and many others.

Also games like Sauerbraten, Nexuiz, Wolfenstein: Enemy Territory, UFO: Alien Invasion and Glest are all very much free and very much playable on Linux these days

8. Misconception: You have to ditch Windows to use Linux

And this is infact the biggest misconception. A lot of Linux distributions also offer a Live CD, which lets you to try Linux even without the installation. All you need to do is download, burn, reboot your PC and off you go. Additionally, there are Live USB flash drives versions. Also if you like it after the trial, these Live distributions give you the option of installing Linux alongside Windows. And this way you can use both operating systems on the same computer with no trouble at all. Linux folks have made sure of that, because they know nobody wants to jump into the unknown.

If you don’t want that, there are always alternatives, like the the Virtual Box, which allows you to install Linux on a virtual machine inside your Windows. Also, nobody’s stopping you from running Virtual Box on Linux and running Windows inside Linux.

Courtesy: listverse


Busting The Biggest Myths About Linux!

Tips On Becoming An Ethical Hacker

Tips On Becoming An Ethical Hacker  
 
When in this profession, never engage in 'black hat' hacking. That means intruding or attacking anyone's network without having full permission.    
Rate this news:  (2 Votes)
Friday, October 04, 2013 If viruses and DDoS attacks tickle your fancy, you might consider becoming a legal hacker or an ethical hacker. Various businesses and government-related organizations are quite serious about their network security and thus need to hire ethical hackers to enhance their networks, applications, and other computer systems to prevent data theft and frauds.

hacking, ethical hacking, hacker, job market, opportunities for hackers, IT career, DDoS, hacking basics, how to become ethical hacker




But, the pertinent question is how does the job market look like for ethical hackers? Well, chances are extremely bright! The IT market continues to grow regardless the recent economic turmoil.

How to get Started

If you are yet to start your IT career, you might even consider going for military service. The military offers several interesting IT opportunities, and you might even get paid to go to school, even when you enlist in a part-time branch such as the National Guard or Reserves.

Start with the basics: You can earn your A+ Certification and go for a tech support position. After gaining some experience and additional certification of (Network+ or CCNA), you can move up to a network support or admin role. After few year, you can move up to the role of a network engineer. Don't stop here! Put in some more time to earn security certifications such as Security+, CISSP, or TICSA and look for information security position. When you're there, focus on n penetration testing--and gain some expertise with the tools of the trade. Now, it's time to work toward the Certified Ethical Hacker (CEH) certification introduced by the International Council of Electronic Commerce Consultants (EC-Council for short). But, spend some time in marketing yourself as an ethical hacker.

It is important for a professional hacker to network. You must discover and play with Unix/Linux commands and distributions. You must ensure you also learn some programming -probably C, LISP, Perl, or Java. You also need to spend some time with databases such as SQL.

Soft Skills

Hacking also requires use of so-called soft skills, just like other IT job. You require strong work ethic, impressive problem-solving and communications skills, and ability to stay motivated in tough times.

Ethical hackers must have people skills and talent for manipulation and should have ability to convince others to reveal credentials.

Stay Legal!

When in this profession, never engage in "black hat" hacking- that means intruding or attacking anyone's network without having full permission. When you engage in illegal activities, it might lead to conviction and end your ethical hacking career.

Becoming a Certified Ethical Hacker (CEH)

In order to become a Certified Ethical Hacker (CEH) you need to earn suitable credential from the EC-Council after gaining few years of security-related IT experience. The certification
will help you gain understanding of security from the mindset of a hacker.

The EC-Council normally requires that you to have around two years of information-security-related work experience which must be endorsed by your employer in addition to passing the exam.

Available Resources

If you are interested ethical hacking, you can check the resources section of the EC-Council site. Moreover, a quick Amazon search will result in several books on ethical hacking and the CEH certification, as well. You can even Google the term to find simple hacking how-tos.

Courtesy: PCWorld.com



Fonte: Tips On Becoming An Ethical Hacker

Siga-nos