Monday, November 28, 2016

Test TCP and UDP with Netcap


Testing TCP connection

Create TCP listener:
$ nc -l 9999
Create TCP Client:
$ nc -vt 192.168.5.12 9999
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 192.168.5.12:9999.


Testing UDP connection

Create UDP listener:
$ nc -ul 9999
Create UDP Client:
$ nc -vu 192.168.5.12 9999
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Connected to 192.168.5.12:9999.

Test UDP Connection only:
$ nc -zvu 192.168.5.12 9999
Connection to 192.168.5.12 9999 port [udp/*] succeeded!

Friday, November 4, 2016

Thursday, November 3, 2016

sysctl to change kernel system settings

To list all settings configurable in the /proc/sys/ directory:

/sbin/sysctl -a


To assign values to writable files in the /proc/sys/ directory:


sysctl -w [parameter] = [value]

Example:

sysctl -w kernel.sysrq="1"

This only works for testing purposes. Special settings within /proc/sys/ are lost when the 
machine is rebooted. To preserve custom settings, add them to the /etc/sysctl.conf file.
Each time the system boots, the init program runs the /etc/rc.d/rc.sysinit script.
This script contains a command to execute sysctl using /etc/sysctl.conf to determine the
values passed to the kernel.




Thursday, October 27, 2016

List the contents of a compressed file without extracting all the files

tar file:

$ tar -tvf file.tar.gz


tar.gz file:

$ tar -ztvf file.tar.gz


tar.bz2 file

$ tar -jtvf file.tar.bz2


List only specific files:

$ tar -tvf file.tar 'pattern'


Where,

t: List the contents.
f: process the following file name.
v: show detailed information.
z: process tar.gz files.
j: process tar.bz2 files.

Wednesday, October 26, 2016

Saturday, October 22, 2016

Wednesday, September 21, 2016

Sunday, September 11, 2016

My CLI CheatSheet


Shorcuts


Ctrl + W - Erase one word in the current line.
!! - Repeats the last command.
Ctrl + Z - Stops the current command,
Ctrl + D - Log out of current session, similar to exit.
Ctrl + K - Deletes from the cursor to the end of the line.

Ctrl + R - Type to bring up a recent command.
Ctrl + U - Deletes from the cursor back to the line start.









Wednesday, August 24, 2016

Edit command from the history list with vi or emacs using fc

fc command is used to edit, re-execute and list previously entered commands from the history list.

With fc you can made a quick open of your favorite editor and edit a previously entered command.

If the command you want to edit just has been resently executed just type:
fc
This open the default editor with the command to edit inside.

Execute with the option -e to choose the editor you want. For example to open with vim, execute:
fc -e vim
If you are inside the editor and you no longer want to execute the command, just quit without saving. For vim editor type :cq.
:cq 
If you want to edit a command that is some lines up of the history list, first use the option -l to show the command list with the line numbers. Then execute fc plus the line number of the command you want to edit. For example:
$ fc -l
994  ls
995  vim main.cpp 
996  set -o vi
997  clear
998  cat myexample.txt
999  cd ..
1000  set -o emacs
1001  ls -l
1002  fc -l
1003  rm 
1004  ls -l
1005  vim test.txt
1006  cd Development
1007  rm mytest
1008  fc -l
1009  mv mytest.txt sometest
$ fc -e vim 998
The former will open the vim editor with the command cat myexample.txt wainting to be edited.

Friday, August 12, 2016

Thursday, July 7, 2016

Screen command quick start guide

To create a new session, write the following with your session name instead of [session]:
screen -R [session]
This will start a new session with name [session](if not created before) in a new clean "screen".

To dettach the session just press:

Ctrl + a  (realease keys) d

To attach the screen session again, write again:
screen -R [session]
To list all the screen sessions:
screen -ls
To kill the current screen:

Ctrl + a  (realease keys) k

Tuesday, July 5, 2016

Command line history

The history command can be used to list all the previous commands you have typed before. The syntax is as following:

history n

where n is the number of commands you have typed before.

Example:
This lists the last 5 commands typed before:
$ history 5
  510  cp /home/pepito/myfile /home/pepito/myfolder
  511  ls
  512  ip addr show
  513  ifconfig
  514  history 5

You can select to execute a command from the list with the following:

!n

Where n is the number of the command in the list.

Example:
This will execute the command number 511 that is the ls command:
$ !511
ls
example.txt

Shortcuts to cut, copy & paste on a terminal command line


Ctrl + u : Deletes from the cursor back to the line start.
.
Ctrl + k : Deletes from the cursor to the end of the line.

Ctrl + w : Deletes until after the previous word boundary.

Alt + d : Deletes until before the next word boundary.

Ctrl + y : Yank/Past the previous killed text at he cursor position.

Alt + y : Yank/Past the previous previous killed text at he cursor position.

More details:
https://en.wikipedia.org/wiki/GNU_Readline

Compress and Extract gz, .tar.gz, and .zip

Compress and Extract gz, .tar.gz, and .zip
.tar.gz:
Compress: tar -czvf file.tar.gz folder/to/compress/
Extract: tar -xzvf file.tar.gz
.tar:
Compress: tar -cvf file.tar folder/to/compress/
Extract: tar -xvf file.tar
.gz:
Compress: gzip -9 file
Extract: gzip -d file.gz
.zip:
Compress: zip file.zip folder/to/compress/
Extract: unzip file.zip

Monday, July 4, 2016

SIOCDELRT error when try to delete a single route from route table

If you want to delete a single route from the route table, you have to specify enough parameters to make this route unique.

For example, this gives you an error, because the mask is not specified:
$ sudo route del -net 192.168.5.0
SIOCDELRT: No such process
This gives you a successful output, because the mask is properly specified:
$ sudo route del -net 192.168.5.0/24

Friday, July 1, 2016

Tuesday, June 28, 2016

Git - Get new recently added files but yet not commited

The following command gets all the files that you recently added but not commited yet:
$ git diff --cached --name-only --diff-filter=A
Details:
--name-only: shows all the files you changed relative to HEAD.
--name-status: to get the status symbol too.
--diff-filter=A: shows only the new recently added files.

Monday, June 27, 2016

Erase all files/directories except some of them

To erase all directories except one, execute the following:
$ find . -maxdepth 1 -not -name [file/directory_name] -exec rm -R {} \;
Where:
-maxdepth: prevents to erase recursively inside the directory to keep.

If you want to be sure that the correct files will be removed, run first the beginning part of the command(before "-exec") and when you are sure, execute the complete command:
$ find . -maxdepth 1 -not -name [file/directory_name]
If you want to keep more than one file/directory, execute:
$ find . -maxdepth 1 -not -name [file_1/directory_name_1] \
-and -not -name [file_2/directory_name_2] -exec rm -R {} \;
Where:
-and: is the logical operand and.

Shortcuts to move the cursor on a terminal command line


Ctrl + a : Moves the cursor to the line start.
.
Ctrl + e : Moves the cursor to the line end (remember e for end).

Alt + f : Moves the cursor forward one word (remember f for forward) .

Alt + b : Moves the cursor backward one word (remember b for backward) .

Ctrl + x + x: Moves the cursor to the line start and to the end again.

More details:
https://en.wikipedia.org/wiki/GNU_Readline

Friday, June 24, 2016

Thursday, June 23, 2016

Git - Checking changes on origin repository against your local

Make a fetch to update the remote branch latest version status in your repository:
$ git fetch origin [Your remote branch]
fetch does not change anything in your local repository, only updates the information against the branch selected.

Check differences with diff:
$ git diff origin/[Your remote branch]

Wednesday, June 22, 2016

Git - Commit project to new branch

Create a new branch and move your project to it:
$ git checkout -b [New Branch]
If you have modified or created files, add them to the project:
$ git add [Your modified or new files]
Commit your changes:
$ git commit -m '[Your Comments]'
Push the project to the new branch:
$ git push origin [New Branch]


See also: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Monday, June 13, 2016

Friday, June 10, 2016

Install Sublime Text 3

Download Sublime Text 3:
wget https://download.sublimetext.com/sublime_text_3_build_3114_x64.tar.bz2
Uncompress tarball:
sudo tar vxjf sublime_text_3_build_3114_x64.tar.bz2
Move sublime directory to /opt:
sudo mv sublime_text_3 /opt/
Create symbolic link to sublime:
sudo ln -s /opt/sublime_text_3/sublime_text /usr/bin/sublime
Execute sublime and enjoy!:
sublime

Thursday, June 9, 2016

Git - Steps to commit a project

1. Show the status(how many new files, deleted files, modified files, etc.):
$ git status
2. Add all files to the project:
$ git add -A
the -A option means track all including deleted files.

3. Commit:
$ git commit -m "[Comments]"
the -m option gives you the possibility to add your comments in the same line.

4. Push:
$ git push -u origin master
The -u is optional and what it does is sets your local repo to a central one in order to, in the next time, git knows where to push and pull from.

For basic snapshotting see:
http://gitref.org/basic/

Thursday, May 19, 2016

Copy command output data to standard output and to a file

Use the tee command: 
 
$ [COMMAND] | tee [OUTPUT.FILE]
 
Where:
 
[COMMAND] is the command you want to execute.
[OUTPUT.FILE] is the file you want to write in.
 
 
Variation for writing the standard error output:
 
$ [COMMAND] 2>&1 | tee [OUTPUT.FILE]
 
Where:
 
[COMMAND] is the command you want to execute. 
[OUTPUT.FILE] is the file you want to write in.
2>&1 redirects stderr(2) to stdout(1).
 
Notes:
2>&1 is different that 2>1.
2>1 means writing to a file with name 1 and 2>&1 means write to the standard output.

Monday, May 9, 2016

Wednesday, March 30, 2016

Configure password-based login for root

By default, the SSH server denies password-based login for root. In /etc/ssh/sshd_config, change:

PermitRootLogin without-password

to

PermitRootLogin yes

And restart SSH:

sudo service ssh restart

Or, you can use SSH keys. If you don't have one, create one using ssh-keygen (stick to the default for the key, and skip the password if you feel like it). Then do sudo -s (or whatever your preferred method of becoming root is), and add an SSH key to /root/.ssh/authorized_keys:

cat /home/user/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys


in some case after change,
   PermitRootLogin yes 
must check this config : 
    DenyUsers root
    AllowUsers saeid

and to enable login must change to :
   #DenyUsers root
    AllowUsers root OtherUser

Tuesday, March 29, 2016

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Blog Archive

Search This Blog

Powered by Blogger.