Assisting 11957441 developers since 2005.

Web Designer, Open Source, Loyal, Dad.  

Read More »

10 Daily Habits That Will Change Your Life -Challenge Accepted

Posted by David  •  Nov 12th, 2014 5:02:20 pm - Subscribe | Mood: good | Music: di.fm

Here are a list of things that I will be doing for the next 2 weeks. Most of this list I do already, but I am going to follow Ben Rodrigue input and do them all.

1. Wake up an hour earlier than you have to.
2. Quiet your mind for 10 minutes.
3. An attitude of gratitude.
4. Write in a Journal.
5. Write a list
6. Exercise
7. Do Affirmations
8. Do something nice
9. Take on a big task
10. Share these ideas with other people

Read more about each one of these on Ben's Blog below, and leave a comment if you have questions or comments.

Source: 10 Daily Habits that will change your life. -seriously

Comments 0  •  Nov 12th, 2014 5:02:20 pm - Subscribe  •  Tweet this entry | Post a comment


What is lsof Command in Linux?

Posted by David  •  Oct 21st, 2014 10:48:15 pm - Subscribe | Mood: spazzy |

This entry explains the user] of the lsof command which stands for, List of Open Files...this can be really useful if you would like to see what files are currently running for the instance of a particular user.

When running lsof it is always a good idea to specify what you are actually looking for, simply running lsof will give you a slew of data much of it will not be useful to you, especially if you are trying to stop a command that is you to properly administer your linux system.

If you can remember I created an entry called Lost Disk Space on Linux Due to Stop Command. In which I was backing up some critical web dev files, not realizing that I was going to be running out of disk. Take a look at that entry, it gives resolution along with the proper use of the lsof command when things go wrong.

Here are a couple of lsof commands that you can use that will help you make heads or tales of what process is doing what, at what time, and at what location.

  • What process is running on what port: lsof -i tcp:80
    quote:
    Output
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    apache2 2493 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    apache2 2586 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    apache2 2587 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    apache2 13376 root 5u IPv6 2015771 0t0 TCP *:http (LISTEN)


  • List all network connections that are listening and established: lsof -i
    quote:
    Output
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    rpcbind 1495 root 6u IPv4 2196 0t0 UDP *:sunrpc
    rpcbind 1495 root 7u IPv4 2199 0t0 UDP *:820
    rpcbind 1495 root 8u IPv4 2200 0t0 TCP *:sunrpc (LISTEN)
    rpcbind 1495 root 9u IPv6 2203 0t0 UDP *:sunrpc
    rpcbind 1495 root 10u IPv6 2217 0t0 UDP *:820
    rpcbind 1495 root 11u IPv6 2218 0t0 TCP *:sunrpc (LISTEN)
    rpc.statd 1527 statd 4u IPv4 2263 0t0 UDP localhost:855
    rpc.statd 1527 statd 7u IPv4 2272 0t0 UDP *:45172
    rpc.statd 1527 statd 8u IPv4 2276 0t0 TCP *:34261 (LISTEN)
    rpc.statd 1527 statd 9u IPv6 2280 0t0 UDP *:39721
    rpc.statd 1527 statd 10u IPv6 2284 0t0 TCP *:58694 (LISTEN)
    sshd 2322 root 3u IPv4 2461758 0t0 TCP 192.168.1.111:ssh->192.171.117.210:60932 (ESTABLISHED)
    apache2 2493 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    ntpd 2574 ntp 16u IPv4 3329 0t0 UDP *:ntp
    ntpd 2574 ntp 17u IPv6 3330 0t0 UDP *:ntp
    ntpd 2574 ntp 18u IPv4 3337 0t0 UDP localhost:ntp
    ntpd 2574 ntp 19u IPv4 3338 0t0 UDP 192.168.1.111:ntp
    ntpd 2574 ntp 20u IPv6 3339 0t0 UDP ip6-localhost:ntp
    ntpd 2574 ntp 21u IPv6 3340 0t0 UDP [fd08:46b3:7999:0:ba27:ebff:fe98:69d7]:ntp
    ntpd 2574 ntp 22u IPv6 3341 0t0 UDP [2605:6000:170c:400b:ba27:ebff:fe98:69d7]:ntp
    ntpd 2574 ntp 23u IPv6 3342 0t0 UDP [fe80::ba27:ebff:fe98:69d7]:ntp
    apache2 2586 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    apache2 2586 www-data 25u IPv6 2470006 0t0 TCP 192.168.1.111:http->c-98-204-186-50.hsd1.md.comcast.net:62561 (FIN_WAIT2)
    apache2 2587 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    miniserv. 2675 root 6u IPv4 156038 0t0 TCP *:55500 (LISTEN)
    miniserv. 2675 root 7u IPv4 156039 0t0 UDP *:55500
    master 2776 root 12u IPv4 3758 0t0 TCP *:smtp (LISTEN)
    master 2776 root 13u IPv6 3760 0t0 TCP *:smtp (LISTEN)
    apache2 13376 root 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    mysqld 19639 mysql 4u IPv4 501203 0t0 TCP localhost:mysql (LISTEN)
    sshd 21336 root 3u IPv4 502704 0t0 TCP *:ssh (LISTEN)
    sshd 21336 root 4u IPv6 502706 0t0 TCP *:ssh (LISTEN)
    sshd 32495 root 3u IPv4 2288516 0t0 TCP 192.168.1.111:ssh->192.168.1.102:56131 (ESTABLISHED)


  • What user is viewing a specific command or file: lsof -i -u david
    quote:
    Output
    COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
    rpcbind 1495 root 6u IPv4 2196 0t0 UDP *:sunrpc
    rpcbind 1495 root 7u IPv4 2199 0t0 UDP *:820
    rpcbind 1495 root 8u IPv4 2200 0t0 TCP *:sunrpc (LISTEN)
    rpcbind 1495 root 9u IPv6 2203 0t0 UDP *:sunrpc
    rpcbind 1495 root 10u IPv6 2217 0t0 UDP *:820
    rpcbind 1495 root 11u IPv6 2218 0t0 TCP *:sunrpc (LISTEN)
    rpc.statd 1527 statd 4u IPv4 2263 0t0 UDP localhost:855
    rpc.statd 1527 statd 7u IPv4 2272 0t0 UDP *:45172
    rpc.statd 1527 statd 8u IPv4 2276 0t0 TCP *:34261 (LISTEN)
    rpc.statd 1527 statd 9u IPv6 2280 0t0 UDP *:39721
    rpc.statd 1527 statd 10u IPv6 2284 0t0 TCP *:58694 (LISTEN)
    sshd 2322 root 3u IPv4 2461758 0t0 TCP 192.168.1.111:ssh->192.171.117.210:60932 (ESTABLISHED)
    apache2 2493 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    ntpd 2574 ntp 16u IPv4 3329 0t0 UDP *:ntp
    ntpd 2574 ntp 17u IPv6 3330 0t0 UDP *:ntp
    ntpd 2574 ntp 18u IPv4 3337 0t0 UDP localhost:ntp
    ntpd 2574 ntp 19u IPv4 3338 0t0 UDP 192.168.1.111:ntp
    ntpd 2574 ntp 20u IPv6 3339 0t0 UDP ip6-localhost:ntp
    ntpd 2574 ntp 21u IPv6 3340 0t0 UDP [fd08:46b3:7999:0:ba27:ebff:fe98:69d7]:ntp
    ntpd 2574 ntp 22u IPv6 3341 0t0 UDP [2605:6000:170c:400b:ba27:ebff:fe98:69d7]:ntp
    ntpd 2574 ntp 23u IPv6 3342 0t0 UDP [fe80::ba27:ebff:fe98:69d7]:ntp
    apache2 2586 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    apache2 2587 www-data 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    miniserv. 2675 root 6u IPv4 156038 0t0 TCP *:55500 (LISTEN)
    miniserv. 2675 root 7u IPv4 156039 0t0 UDP *:55500
    master 2776 root 12u IPv4 3758 0t0 TCP *:smtp (LISTEN)
    master 2776 root 13u IPv6 3760 0t0 TCP *:smtp (LISTEN)
    apache2 13376 root 5u IPv6 2015771 0t0 TCP *:http (LISTEN)
    mysqld 19639 mysql 4u IPv4 501203 0t0 TCP localhost:mysql (LISTEN)
    sshd 21336 root 3u IPv4 502704 0t0 TCP *:ssh (LISTEN)
    sshd 21336 root 4u IPv6 502706 0t0 TCP *:ssh (LISTEN)
    sshd 32495 root 3u IPv4 2288516 0t0 TCP 192.168.1.111:ssh->192.168.1.102:56131 (ESTABLISHED)


    Well I hope this brief snippet of information shows you how useful the lsof command can be, if you have any commands that you would like to share, leave a comment below.

    Comments 0  •  Oct 21st, 2014 10:48:15 pm - Subscribe  •  Tweet this entry | Post a comment


  • How to Create And Mount A Disk Partition in Linux

    Posted by David  •  Oct 5th, 2014 9:29:59 pm - Subscribe | Mood: introspective | Music: Reggie and the Full Effect - Sundae Booty Sundae

    This short entry explains how to create a mount a disk partition in linux. I will show you how to mount a peripheral such as a USB stick, External Drive, or anything else that can be easily remove from your Linux machine. Let’s get started.

    What you will need:

  • Linux operating system
  • USB stick or external drive
  • Approximately 5 to 10 mins of time

    Basics
  • Begin by logging into your linux system as su
  • Su - (this will give you uninterrupted access to run commands)
  • Navigate to /home/{yourusername} by typing in cd /home/{yourusername}
  • Create a directory called mount: mkdir mount

    Peripherals
  • Navigate to the dev directory on your linux system: cd /dev
  • Now we need to list the files in the /dev directory by executing the command: ls
  • Plug in your usb stick / external drive to your linux system (depending on size this may take a few seconds for the machine to fully recognize your device)
  • Now type the list command: ls
  • Do you notice a new device listed? For example mine is called xvdj your’s will be called something different.
  • Once you have located the name of the device {xvdj} we need to mount it to our /home/{yourusername} directory

    Specify a File System
    In linux there are many types of file systems, but we will talk about. ext2, ext3, ext4. ext2 is the native file system on your linux machine, if you do not specify ext2 your linux system will default to this. ext3 is much like ext2, but that it allows journaling. Journaling does exactly that, it will log the commands and actions that you do. This will allow you recover a file / directory should it be accidently deleted. (this is in no way to be used as a backup utility) ext4 will allow you to create a file system that is up to: 32TB large and will support a file up to: 2TB big. So now that you no some of the differences, lets specify.

  • Begin by enter the command, be sure to change {xvdj} to your device name that your system has given it: mkfs -t ext3 /dev/{xvdj} Keep in mind that running this command can either go fast or slow so be patient. Once it completes, your disk volume will now be formatted with the file system: ext3
  • Optional: You have the ability in the command above to pass the -m {#} flag to change the reserve disk space (this prevents a system crash when the director is full), and the -c flag will add a bad block check, which means every sector on the partition of the device will be checked to see if it can be trusted to reliability hold data. (good for old drives)

    Mounting
  • Navigate back to our /home/{username} by typing cd /home/{yourusername}
  • You will notice if you run the ls command that our mount directory is here. So what we are going to do is mount our /dev/{xvdj} to /home/{username}/mount this will give us the ability to see our devices content in our users mount directory.
  • To mount the device we will enter: mount /dev/{xvdj} /home/{yourusername}/mount now hit enter.
  • If you received an error stating: mount: you must specify the file system type. Then go back to Specify a File Systems in the list above.
  • You're done! You have now mounted a device to your linux file system.

    Unmounting
    If you wish to unmount the device/peripheral from your linux system enter the following command.

  • umount /home/{yourusername}/mount (be sure that you are not in the directory when running this, or the device is not running a process when executing the command) If it is you will get an error that says: umount: /home/{yourusername}/mount: device is busy

    Notice
    Just a heads up that mounting a device in this manner will disconnect upon reboot...see my next post on how to prevent that from happening.

    Comments 0  •  Oct 5th, 2014 9:29:59 pm - Subscribe  •  Tweet this entry | Post a comment


  • mkfs.ext3: Permission denied while trying to determine filesystem size

    Posted by David  •  Oct 4th, 2014 9:33:27 pm - Subscribe | Mood: tired | Music: No Music

    While trying to mkfs I received an error: Permission denied while trying to determine filesystem size.

    mkfs.ext3: Permission denied while trying to determine filesystem size

    This is a quick entry, I wanted to mount a device to my Linux system, but I received the error:

    Error
    mkfs.ext3: Permission denied while trying to determine filesystem size

    I was sure why this was outside of the obvious permission denied, but my focus was on the filesystem size part of this error. Why was it taking so long to determine the filesystem size I thought?

    Well, it does NOT have to do with the file system size of the device, but it on the first two words of the error. Permission denied. I solved this problem by not being an end user with no permissions to the system, I became a super user by executing su -. I then tried my command again:

    Make File System ext3 on Device
    mkfs -t ext3 /dev/xvdj

    Success! The out was:

    My lesson learned here was not to assume always that you have access to everything. You are not always a super user and you should never run as root in production.

    Comments 0  •  Oct 4th, 2014 9:33:27 pm - Subscribe  •  Tweet this entry | Post a comment


    Remove Banned IP from Fail2Ban on Ubuntu / Raspberry Pi

    Posted by David  •  Sep 27th, 2014 10:10:12 pm - Subscribe | Mood: Studying | Music: No music

    If you have never used Fail2Ban on your Linux distro. I would greatly recommended it, especially if you seeing a lot of traffic trying to brute force your standard SSH connection.

    Good practice:
    1. Do not SSH on port 22
    2. Do not use root
    3. Disable root

    But this entry is not on good practices on SSH connections, but rather how to remove a ban that Fail2Ban may have done to block you, a client, or a connection that was not intended to be blocked.



    Begin by doing the following:
    1. iptables -L (Do you see your ip in this list?)
    2. iptables -D fail2ban-ssh -s xxx.xxx.xxx.xxx -j DROP
    3. Where you see xxx.xxx.xxx.xxx add the IP that is banned.
    4. Now verify that your IP is no longer in the list: iptables -L



    That's it! Your IP should now be removed! To prevent this from happening again, navigate to the follow path and add your IP address to the safe list:

    1. cd /etc/fail2ban
    2. vi fail.conf
    3. Now locate: # "ignoreip" can be an IP address, a CIDR mask or a DNS host
    4. Add your IP address to this list
    5. Now save with a :x

    I hope this helps you, if you have questions drop me a comment below.

    Comments 0  •  Sep 27th, 2014 10:10:12 pm - Subscribe  •  Tweet this entry | Post a comment



    Image Gallery

    Badges


    Amazon Wishlist Stumble Upon Toolbar
    Internet Blogs - Blog Top Sites Internet Blogs - Blog Top Sites Technology

    About Me

    avatar

    @davidpolanco
    iPhone: 29.513522,-98.565523 Web Designer, Open Source, Loyal, Dad. Learn more...