Filter by tag Linux

Number of results: 5
  • Linux & Server Administration

    11 comments

    Finding files

    $ grep -rnw '/path/to/somewhere/' -e 'pattern'
    
    • -r or -R is recursive,
    • -n adds line numbers,
    • -w stands for match the whole word,
    • -l (lower-case L) can be added to just give the file name of matching files

    Ref: How do I find all files containing specific text on Linux? - https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux

    Network

    Show ports based on PID of a process

    $ sudo netstat -tulpn | grep ${PID}
    

    Show information about CPU

    $ cat /proc/cpuinfo
    

    Check the connection to the server and open port on a specific remote computer

    $ telnet SERVER_ADDRESS PORT
    

    Connect to a remote server, the best way through the command 'ssh'

    $ ssh USER@SERVER_ADDRESS
    

    Less

    Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Useful commands when browsing logs:

    • Waiting for latest lines at EOF - SHIFT + F
    • Finish of waiting at EOF - CTRL + C
    • Search for a specific text - /${TEXT}
    • Leave or finish - Q

    Nano

    GNU nano is a small and friendly text editor. Besides basic text editing, nano offers many extra features like an interactive search and replace, go to line and column number, auto-indentation, feature toggles, internationalization support, and filename tab completion.

    • Search for a specific text - CTRL + W

    Grep

    grep is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression and print), which has the same effect: doing a global search with the regular expression and printing all matching lines. Grep was originally developed for the Unix operating system, but later available for all Unix-like systems.

    grep -E option is for extended regexp. If you use the grep command with -E option, you just need to use | to separate multiple patterns for the or condition.

    $ ps aux | grep -E 'ssh|PID'
    

    It is useful for the showing the title of listing processes when filter for a specific command.

    Read More
  • Quartz Sheduler - Cron Trigger

    11 comments

    Cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerful and proven. The CronTrigger class is based on the scheduling capabilities of cron.

    CronTrigger uses “cron expressions”, which are able to create firing schedules such as: “At 8:00am every Monday through Friday” or “At 1:30am every last Friday of the month”.

    1. Seconds
    2. Minutes
    3. Hours
    4. Day-of-Month
    5. Month
    6. Day-of-Week
    7. Year (optional field)

    Cron examples:

    • 0/30 * * * * ? = every 30s from 0s
    • 0 0 8 * * ? = every day at 8h am
    • 0 15 9 ? * MON = every Monday at 9h 15m am

    Ref: Quartz Sheduler: Cron Trigger Tutorial - http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html

    Read More
  • SSH key

    11 comments

    Generate SSH keys via the 'ssh-keygen' command. SSH settings are stored in the '~/.ssh/' directory.

    1. Run ssh-keygen
    2. Keep the name 'id_rsa' and type a password
    3. Generating our public key
    4. Upload the public key on BitBucket
    5. Set SSH url to SourceTree

    Ref: Gavin Picking: Git for Dummies - Creating your SSH Keys for Bit Bucket - http://www.gpickin.com/index.cfm/blog/git-for-dummies-creating-your-ssh-keys-for-bit-bucket

    Adding a Private Key to Your Mac OSX Keychain

    If you have a problem with a SSH connection in Mac OS X to the remote server like:

    Error - Permission denied (publickey). Fatal: Could not read from remote repository.
    

    Add the SSH key to your KeyChain:

    ssh-add -K /path/of/private/key
    

    Ref: HPCC Confluence: Adding a Private Key to Your Mac OSX Keychain - https://wiki.hpcc.msu.edu/display/hpccdocs/Adding+a+Private+Key+to+Your+Mac+OSX+Keychain

    Read More
  • Crack WEP Wi-FI via aircrack-ng in Mac OS X

    11 comments

    Display all network interfaces

    ifconfig
    

    Display nearby networks with additional parameters

    airport -s
    

    Sniff packets on a network interface and a channel, save it to /tmp/airport*.cap

    sudo airport {networkInterface} sniff {channel}
    e.g. sudo airport en0 sniff 6
    

    Find the password (1 attempt)

    aircrack-ng -1 -a 1 -b {bsid} {filepath}
    e.g. aircrack-ng -1 -a 1 -b 00:02:72:UV:WX:YZ /tmp/airportSniffVO0t4J.cap
    

    Founded passwords:

    AP-HOME 00:02:72:UV:WX:YZ -78  13      N  -- WEP
    [ 01:23:45:67:89 ] (ASCII: PASSWORD )   [02:05:34] Tested 199 keys (got 15014 IVs)
    

    Prerequisites

    1. Install Macports.
    2. Install aircrack-ng:
      sudo port install aircrack-ng
    3. Install the latest Xcode, with the Command Line Tools.
    4. Create the following symlink:
      sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
    5. Figure out which channel you need to sniff:
      sudo airport -s
      sudo airport en1 sniff [CHANNEL]
    6. New Terminal Window
      aircrack-ng -1 -a 1 -b [TARGET_MAC_ADDRESS] [CAP_FILE]
      //Notes: the cap_file will be located in the /tmp/airportSniff*.cap

    Ref: Jason4Zhu: Way To Crack WEP Wifi Via Aircrack-ng In Mac OSX - http://jason4zhu.blogspot.cz/2014/12/crack-wep-wifi-via-aircrack-ng-in-mac-osx.html

    Read More
  • Sign automatically git commits

    11 comments

    Edit a git config file in $HOME/.gitconfig or in a project folder .git/config like following:

    [user]
    email = YourEmail
    name = YourName
    signingkey = YourSigningKey
    [commit]
    gpgsign = true
    [gpg]
    program = /Applications/SourceTree.app/Contents/Resources/bin/stgpg.sh
    

    Ref: Atlassian Answers: Possible to GPG sign commits by default? - https://answers.atlassian.com/questions/38060409/possible-to-gpg-sign-commits-by-default

    If you want to verify the signed signatures, you will be able to show them with --show-signature option.

    $ git log --show-signature
    

    Ref: Git Tools - Signing Your Work: https://git-scm.com/book/tr/v2/Git-Tools-Signing-Your-Work

    Steps how to fix an unsigned commit

    1. None of the developers may commit anything during the operation
    2. Create a backup branch (master-backup)
    3. Checkout the master
    4. Hard reset to commit before the unsgned commit
    5. Merge the same way the branch (copying source files from master-backup)
    6. Sign the unsigned commit
    7. Add all other commits by Cherry pick
    8. Check differences with a diff tool
    9. Pull all changes to the remote server
    10. For each developer, make a hard reset to commit before unsigned
    11. Pull the changed git commits from the remote
    Read More