Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2019-01-09

tmux vs screen

I was a big fan of screen but against RHEL8 I have to move on tmux. Is is ok, by my finger memory have been adjusting to screen configuration, so there is a .tmux.conf with screen binding.
unbind C-b
### change default prefix to screen prefix C-a
set -g prefix C-a
set -g status-bg black
set -g status-fg white
set-window-option -g window-status-current-bg white
set-window-option -g window-status-current-fg black
set-window-option -g window-status-current-attr bold
set -g status-left '#[fg=colour80](#S) #(whoami) '
set -g status-justify centre
bind-key C-a last-window
bind-key C-c new-window
bind-key space next-window
bind-key bspace previous-window
bind a send-prefix
### set mouse on with prefix+m and off with prefix+M 
bind m \
    set -g mouse on \;\
    display 'Mouse: ON'
bind M \
    set -g mouse off \;\
    display 'Mouse: OFF'

2011-06-22

LINUX BASH

Set


set -xDisplay commands and their arguments as they are executed. +x turn off
set -vDisplay shell input lines as they are read. +v turn off





Params


$?error code
$#a number of params
$@list params
$*list params
$0script name
$1param nr 1
$$process ID





Keybindings


S-M-$complete variable
S-<first command in history
C-pprevious command in history
C-nnext command in history
S->last command in history
C-ejump to EOL
C-ajump to BOL
M-fjump forward a word
M-bjump back a world
C-udelete from BOL to cursor
C-kdelete from cursor to EOL
M-ddelete word forward from cursor
C-wdelete word backward from cursor




Variable manipulation


  • (command1; command2;…) #command inside brackeds are lauched in subshell with new process id(childs)
    subshell variables are recognized in subshell only
  • ${var}
  • ${#var} #a number of variable var characters


commandoutputdesc
export var=(el1 el2 el3); echo ${var[1]}val2the second element var variable, which is a list
export var=(el1 el2 el3); echo ${#var[1]}4a number of chars in the second element
export var=(el1 el2 el3); echo ${#var[@]}3list size
export var=12345; echo ${var:-text}if var was set the output is var value, if not the output is text, var is not change
export var=12345; echo ${var:=text}if var was set the output is var value, if not the output is text, var is changed to text
export var=12345; echo ${var:?text}if var was set the output is var value, if not the output is text to the error output
export var=12345; echo ${var:+text}if var was set the output is text, var is not change
export var=12345; echo ${var:1:3}234get second element (first is 0) and next 3
export var=12345; echo ${var#12}345remove elements based on schema 12 from the begining
export var=12345; echo ${var%45}123remove elements based on schema 45 from the end
export var=12345; echo ${var/34/ab}12ab5substitute elements by pattern 34 to ab anywhere
export var=12345; echo ${var/#12/ab}ab123substitute elements by pattern 12 to ab from the beggining
export var=12345; echo ${var/%45/ab}123absubstitute elements by pattern 45 to ab from the end





Array


  • Array=(el01 el02 el03)
  • element at the table is matched by [] symbol and by ${Array[0]}
  • iteration: for i in ${Array[@]};do echo $i; done




Buildin variables and commands


zmiennadesc
BASH_SUBSHELLsubshell nr
SECONDSamount of time running script
FUNCNAMEfuction name
DIRSTACKcurrent dir
LINENOcurrend row
:true
PWDcurrent dir
CDPATHcd command path
TMOUTlogout after [sec] of inactivity





Debug


bash -n [script]set -ncheck without run
bash -x [script]set -xdebug




Range variable


  • function inherits variables from script
  • script do not inherit variable from function
  • script inherit variable from for loop




Function


  • {} #anonymous function, variables from script
  • in {} there is the block of code which output might be redirect to file {} > output.file,
    block of code from {} is not placed in subshell like for ()




Test




[[


  • less suprises, safer to use, but it is not portable, not POSIX only bash,
    regexp matching, it is a keyword, not a program
  • string comparision:

    <, >, =, ==, !=
  • integer comparison:

    -lt, -le, -eq, -ge, -gt, -ne
  • conditional evaluation:
    &&, ||
  • expression grouping:

    (…)



[


  • right side must be quote ex. if [ -z "$variable ], is sysnonym for test but
    requires a final ], it is a program /usr/bin/[
  • string comparision:

    \<, \>, =, !=
  • integer comparison:

    -lt, -le, -eq, -ge, -gt, -ne




files


-f filetrue if file exists and is a regular file
-e filetrue if file exists
-d filetrue if file exists and is a directory





strings


-z stringtrue if the length of string is zero
-n stringtrue if the length of string is non-zero





using


  • [ c1 ] ||/&& [ c2 ]
  • both alternatives are different ex:
    c1c2
    andOKis run
    andFAILis not run
    orOKis not run
    orFAILis run






Getopts


variabledescription
OPTINDHolds the index to the next argument to be processed. This is how getopts "remembers" its own status between invocations. Also usefull to shift the positional parameters after processing with getopts. OPTIND is initially set to 1, and needs to be re-set to 1 if you want to parse anything again with getopts
OPTARGThis variable is set to an argument for an option found by getopts, but if the option is unknown it contains the option flag.
OPTERR(Values 0 or 1) Indicates if Bash should display error messages generated by the getopts builtin. The value is initialized to 1 on every shell startup - so be sure to always set it to 0 if you don't want to see annoying messages!


  • getopts OPTSTRING VARNAME [ARGS…]
    OPTSTRINGtells getopts which options to expect and where to expect arguments (see below)
    VARNAMEtells getopts which shell-variable to use for option reporting
    ARGStells getopts to parse these optional words instead of the positional parameters


  • commands without any args - nothing happened? Right. getopts didn't see any valid or invalid options (letters preceeded by a dash),
    so it wasn't triggered.
  • commands without any flags - nothing happened? The very same case: getopts didn't see any valid or invalid options
    (letters preceeded by a dash), so it wasn't triggered.
  • invalid options don't stop the processing: If you want to stop the script, you have to do it yourself (exit in the right place)
  • multiple identical options are possible: If you want to disallow these, you have to check manually (e.g. by setting a variable or so)




OPTSTRING


  • When you want getopts to expect an argument for an option, just place a : (colon) after the proper option flag.
  • If the very first character of the option-string is a : (colon), which normally would be nonsense
    because there's no option letter preceeding it, getopts switches to the mode "silent error reporting".
    In productive scripts, this is usually what you want (handle errors yourself and don't get disturbed by annoying messages).




ARGS


  • The getopts utility parses the positional parameters of the current shell or function by default (which means it parses "$@").
    You can give your own set of arguments to the utility to parse. Whenever additional arguments are given after the VARNAME parameter,
    getopts doesn't try to parse the positional parameters, but these given words.
    A call to getopts without these additional arguments is equivalent to explicitly calling it with "$@".




Calculate


  • echo $((2+3))



Return status


  • last command at function or script determe exit status, thisis bash return value
  • exit status might be at range 0-255




Commands


evalchange string from variable to command ex. i="ls"; eval $i
sourcefrom command line run script, from script working as #include (same as dot-command)
execdo not create fork but create new shell process, go out from script
true,falsereturn 0 as exit status of error
help [bash_command]help for bash commands ex. help eval





Output




ex 1: command > /dev/null 2>&1


  1. redirect standard output /dev/stdout to /dev/null
  2. redirect standard error /dev/stderr to device point at standard output /dev/stdout, so to /dev/null

Summarize: all output is redirect to /dev/null



ex 2: command 2>&1 > /dev/null


  1. redirect error output /dev/stderr to device point at standard output /dev/stdout
  2. redirect standard ouptut /dev/stdout to /dev/null but error output /dev/stderr
    is still redirected to /dev/stdout

Summarize: /dev/stdout to /dev/null and /dev/stderror to previous /dev/stdout



Printf


  • printf "%-30s%s" "hello" $VAR




Colors in directory


  • dircolors -p ~/.dircolors
  • eval `/usr/bin/dircolors -b ~/.dircolors`
  • alias dir="dir –color"
  • alias ls="ls –color"



color symbols


descatrybut
none00
bold01
underscore04
blink05
reverse07
concealed08
font kolorbackground color
black3040
red3141
green3242
yellow3343
blue3444
magenta3545
cyan3646
white3747


2011-02-16

LINUX NETWORK

Turn off NetworkManager:

  • chkconfig NetworkManager off
  • systemclt disable NetworkManager.service

Setting gateway:

/etc/sysconfig/network

NETWORKING=yes
HOSTNAME=[hostname]
GATEWAY=[IP]

Bonding module:

/etc/modprobe.d/bond.conf

alias bond0 bonding
options bond0 miimon=100 mode=1

Setting ordinary interfaces:

/etc/sysconfig/network-scripts/ifcfg-[dev_name]

DEVICE=[dev_name]
BOOTPROTO=none
HWADDR=AA:AA:AA:AA:AA:AA
ONBOOT=yes
MASTER=bond0
SLAVE=yes
NM_CONTROLLED=no

Setting bond interfaces

/etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
IPADDR=[IP]
NETMASK=[MASK]
IPV6INIT=no
NM_CONTROLLED=no

iwlist

  • iwlist [interface] frequency

WIFI - wpa_supplicant

wpa_passphrase

  • wpa_passphrase "[ssid]" "[passphrase]" #generating psk key which is used by wpa_supplicant.conf

wpa_supplicant.conf

/etc/wpa_supplicant/wpa_supplicant.conf

network={
  ssid="leny"
  #psk="[opentext_passphrase]"
  psk=[psk_from_wpa_passphrase]
  scan_ssid=1
  proto=WPA2 #WPA RSN
  priority=1
  scan_ssid=1 #if ssid is hidden
  #key_mgmt=WPA-EAP
  #key_mgmt=WPA-PSK
}

lanunch wifi steps:

  1. ip link set [dev_name] up
  2. iw [dev_name] scan
  3. wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -Dwext -i[dev_name] -B #run as daemon (-B flag)
  4. dhclient [dev_name]
  5. ip addr show [dev_name]
  6. route add default gw [IP]

2010-12-21

LINUX INFO

Table of Contents

1 Commands

nnext the same level
pprevious
]next deeper
[previous
ttop
ddirectory
llast
rother way of last
Lhistory
mmenu
tabpositions in menu
freference
ssearch
iindex
ggo to node
nmove to the "next" node of this node
pmove to the "previous" node of this node
mpick menu item specified by name (or abbreviation), picking a menu item causes another node to be selected
dgo to the Info directory mode
<go to the top node of this file
>go to the final node in this file
[go backward one node, considering all nodes as forming one sequence
]go forward one node, considering all nodes as forming one sequence
tabmove cursor to next cross-reference or menu item
M-TABmove cursor to previous cross-reference or menu item
ffollow a cross reference. Reads name of reference
lmove back in history to the last node you were at/td>
rmove forward in history to the node you returned from after using l
Lgo to menu of visited nodes
Tgo to table of contents of the current Info file

2010-04-16

LINUX PASSWORD POLICY

1 Password strength:

  1. check pam module pam_cracklib.so in /lib/security
  2. edit /etc/pam.d/system-auth
    • password requisite pam_cracklib.so try_first_pass retry=3 minlen=8 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1
      retryattempts to pick new password
      minlenmin password length
      ucreditupper case -1 means at least 1
      lcreditlower case
      ocreditspecial character
      dcreditdigit


2 Password duration:

  • For new accounts default settings are in /etc/login.defs
  • Settings for current accounts are in /etc/shadow but we edit by command chage

2.1 chage

chage -l [user]check settings for user
chage -E "YYYY-MM-DD" [user]set date when account expire, -1 means never
chage -M [nr] [user]set maximum number of days between password change from last password change, -1 means never expire
chage -d "YYYY-MM-DD" [user]set last password change
chage -W [nr] [user]number of days of warning before password expires
chage -i [nr] [user]set password inactive, when account is blocked after password expire

3 Password repeat history:

  • edit /etc/pam.d/system-auth
    • password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=2
      remembernumber of password in history file /etc/security/opasswd


4 Login attempts:

  • check pam module pam_tally2.so in /lib/security
  • edit /etc/pam.d/system-auth
    • auth required pam_tally2.so deny=3 unlock_time=60 lock_time=5
      denynumber of attempts to log without deny
      unlock_timetime in sec when next login attempt perform
      lock_timetime in sec when delay every failed login attempt
    • all logs about login attempts are in /var/log/tallylog but we edit by command pam_tally2

4.1 pam_tally2

pam_tally2 -u [user]check failed login attempts
pam_tally2 -r -u [user]reset failed login attempts

2009-10-23

LINUX PACKAGES

Packages

RPMYUMDPKGDESCRIPTION
rpm -q –changelog [package]changelog
rpm -U/-i –test [package].rpmtest before install
rpm -qa –last | headinstallation time of last packages
rpm -ql [package]dpkg -L [package]file list installed by package
rpm -qf [file]yum provides [file]dpkg -S [file]package name which is owner of file
rpm -qi [package]yum info [package]dpkg -s [package]info
rpm -q [package]dpkg-query -W [package]package version
rpm -qayum list installeddpkg –listinstalled packages
yum list [package]available packages in repository (about 15000), or package version in repo
rpm -q –whatrequires [package]package needs
rpm -q –provides [package]search missing libs, files
rpm -q –whatprovides libc.so.6yum list provides [shared_obj]
yum whatprovides "\*bin/[file]"search in which package is file
yum whatprovides libpthread*
yum list extrasunoficial repo packages list
rpm -qR [pakiet]yum deplist [pakiet]dependency list
yum check-updateupdate check
yum list updates
rpm -qp –scripts [package].rpmscripts check
rpm -qlp [package].rpmrpm content check
yum -Cusing cache
yum search [string]search by names, descriptions, summaries
yum list [string]\*search by [string]
yum history
yum-complete-transactioncomplete transaction after power crash etc.
yum-complete-transaction –cleanup-onlyclean transaction without resume the aborted transactions
yum clean allremove all traces of the version from /var/cache/yum
yum –releasever=[release_nr_to_sync] distro-sync
yum –rebuilddbrebuild rpm database, recreate database index

yum history

yum history listlast 20 transactins
yum history list allall transactions
yum history list [ID]
yum history info [ID]all info about transaction
yum history package-list [package_name]

Action column

DDowngradeAt least one package has been downgraded to an older version.
EEraseAt least one package has been removed.
IInstallAt least one new package has been installed.
OObsoletingAt least one package has been marked as obsolete.
RReinstallAt least one package has been reinstalled.
UUpdateAt least one package has been updated to a newer version.

Altered column

<Before the transaction finished, the rpmdb database was changed outside Yum.
>After the transaction finished, the rpmdb database was changed outside Yum.
*The transaction failed to finish.
#The transaction finished successfully, but yum returned a non-zero exit code.
EThe transaction finished successfully, but an error or a warning was displayed.
PThe transaction finished successfully, but problems already existed in the rpmdb database.
sThe transaction finished successfully, but the –skip-broken command line option was used and certain packages were skipped.

Misc

rpmreapertool for removing packages and find dependencies
package-cleanup –orphansunsupported packages
yumdownloader [package]get rpm package
yumdownloader –source [package]getsource package
rpm2cpio [package].rpm | cpio -idvunpack rpm2cpio
rpm2cpio [package].rpm | cpio -twhat is inside rpm
yum grouplistzainstalowane i dostepne grupy
yum groupinstall '[group]'instalacja grupy
yum groupinfo '[group]'
yum groupremove '[group]'
yum –downloadonly updatedownload only
rpm –querytagsshow all tags
rpm -qa –queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n"
rpm -qa –queryformat "%{NAME}-%{VERSION}-%{RELEASE}\t%{INSTALLTIME:date}"
rpm -qa –queryformat "%-40{NAME}%-20{VERSION}%-20{RELEASE}%{INSTALLTIME:date}\n"

Remarks

  • For RPM repos main database is located in /var/lib/rpm, it is BerkleyDB.

2009-08-13

LINUX LVM

1 Create LVM partition

1.1 Create LVM partition:

  • fdisk /dev/[disk]
  • change partition type from LINUX to LVM

1.2 Initialize LVM partition:

  • pvcreate /dev/[disk_partiton1] /dev/[disk_partition2]
  • verifycommands:
    • pvs
    • pvdisplay

1.3 Create LVM group:

  • vgcreate [group_name] /dev/[disk_partition1] /dev/[disk_partition2]
  • verify commands:
    • vgs
    • vgdisplay

1.4 Create logical volumes which is attached to group:

  • lvcreate -L[size]M -n [vol_name] [group_name]
  • verify commands:
    • lvs
    • lvdisplay

1.5 Volume format:

  • mkfs.ext3 [lv_name_from_lvdisplay]

2 Snapshot

2.1 Desc

  • Snapshot covers process of writing block to special area before writing to this block, so if you want to make changes to block at first you must copy this block to special area
  • So it is neccesary to set volume snapshot size, and when it will be full the snapshot is broken

2.2 Steps

  1. lvcreate -s -L[size]G -n [lv_snap] /dev/[vg_name]/[lv_2snap]
  2. dd if=/dev/[vg_name]/[lv_snap] of=[file_name].img
    • The size of file is similar to "lvdisplay /dev/[vg_name]/[lv_snap]"
    • If snapshot size is oversized the warning is "input/ouput error"
  3. lvcreate -n [lv_new] -L[size_bigger_then_above] [vg_name]
    • It is possible to expand by resize2fs
  4. dd if=[file_name].img of=/dev/[vg_name]/[lv_new]
  5. lvremove /dev/[vg_name]/[lv_snap]

3 Move data inside group

  1. pvs
  2. pvmove /dev/sd...
  3. pvs

4 Remove disk from group

  • lvreduce [vg_name] /dev/sd...

5 Add disk to group

  1. pvcreate /dev/sd...
  2. pvs
  3. vgextend [vg_name] /dev/sd...

6 Reduce volume size

  1. umount...
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name]/[lv_name] [nr]G
  4. lvreduce -L[nr]G /dev/[vg_name]/[lv_name]
  5. mount...

7 Extend volume size

  1. lvextend /dev/[vg_name]/[lv_name]
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name\/[lv_name]

8 Activate group

  • vgscan
  • vgchange -ay

9 Extend partition

  • fdisk
  • d #remove partition
  • n #make a new one with start section at the same point

2009-07-24

LINUX MUTT

2 .muttrc

  • http://dev.mutt.org/trac/wiki/ConfigLits
    CONFIGURATIONDESCRIPTION
    set move=nodont ask about moving message to mbox
    set imap_user =imap username
    set imap_pass =imap password
    set folder =main folder like "imaps://[hostname]"
    set ssl_starttls = yes
    set smtp_url =url lik smtp://[hostname]:25/
    set smtp_pass ="$imap_pass"
    set spoolfile ="+INBOX"
    set realname =name
    set from =name
    set record =folder for outgoing messages
    set copy = nocopy outgoing messages to above folder
    set pager_stop = yesdo not move to the next message during reading
    my_hdr From: <mail@domain>set header
    #my_hdr CC: <mail@domain>
    my_hdr Reply-to: <mail@domain>
    my_hdr User-Agent: Mutt
    set header_cache=~/.hcacheset file for source headers
    source /[path]/[filename]split config for many files
    set date_format="%b-%d %H:%M:%S"
    set index_format="%-4C%-5Z%-17d%-30a%s"index format
    auto_view text/html
    bind index "q" noop
    bind index "x" exit
    save-hook '~s [title]' "$folder/[folder]"set filter for saving directory
    alias [alias] email@domainset alias recipients, during sending put TAB
    color header brightyellow default "^date:"header coloers
    color header brightred default "^from:"
    color header white default "^to:"
    color header white default "^cc:"
    color header brightyellow red "^subject:"
    color status white black


3 OS mode

mutt -f imap://[IMAP_server]/inboxlogon to IMAP server

4 Main mode (index)

COMMANDDESCRIPTION
source [config_file]reload config
$run command, save mailbox, refresh
@show sender address
osort
entershow message
dmark to delete
Dmark to delete based on regexp
uunmark delete
Uunmark delete based on regexp
rreply
greply all
msend
=first message
kprevious message
fnext message
jnext message
*last message
nmessage nr [n]
C-gclean command line
cchange directory, ? - directory list
ssave message
vshow attachement
wset flag
Wunset flag
ttag message
Ttag messag based on regexp

4.1 index_format

  • default: %4C %Z %{%b %d} %-15.15L (%4l) %s
  • my: set index_format="%-5Z%-17d%-30a%s"
  • set date_format="%m-%d %H:%M:%S" #zgodne z strftime
    %aaddress of the author
    %bfilename of the original message folder (think mailBox)
    %Bthe list to which the letter was sent, or else the folder name (%b).
    %cnumber of characters (bytes) in the message
    %Ccurrent message number
    %ddate and time of the message in the format specified by ``date_format'' converted to sender's time zone
    %Ddate and time of the message in the format specified by ``date_format'' converted to the local time zone
    %ecurrent message number in thread
    %Enumber of messages in current thread
    %fentire From: line (address + real name)
    %Fauthor name, or recipient name if the message is from you
    %imessage-id of the current message
    %lnumber of lines in the message
    %LIf an address in the To or CC header field matches an address defined by the users ``lists'' command, this displays "To <list-name>", otherwise the same as %F.
    %mtotal number of message in the mailbox
    %Mnumber of hidden messages if the thread is collapsed.
    %Nmessage score
    %nauthor's real name (or address if missing)
    %O(_O_riginal save folder) Where mutt would formerly have stashed the message: list name or recipient name if no list
    %ssubject of the message
    %Sstatus of the message (N/D/d/!/r/*)
    %t`to:' field (recipients)
    %Tthe appropriate character from the $to_chars string
    %uuser (login) name of the author
    %vfirst name of the author, or the recipient if the message is from you
    %y`x-label:' field, if present
    %Y`x-label' field, if present, and (1) not at part of a thread tree, (2) at the top of a thread, or (3) `x-label' is different from preceding message's `x-label'.
    %Zmessage status flags

5 Message mode(pager)

iexit
[SPC]next page
-prev page
vattach

6 Flags

FLAGDESCRIPTION
Dmark to delete
Nnew, not read
Oold, but not read
*marked
PPGP included
rreplied to
+message only for you
Tmessage for you with CC field
Cyou are at CC field
Fmessage from you
Lmassage from subscribe list

7 Tagging

Ttag message based on regexp
;(semi-colon)apply operation form tagged messages
Wchange flag

8 Keybinding

  • edit muttrc ex.
    bind index "q" noop #means not bind "q" key with index mode

9 Patterns for messages

~Aall messages
~b EXPRmessages which contain EXPR in the message body
~B EXPRmessages which contain EXPR in the whole message
~c USERmessages carbon-copied to USER
~C EXPRmessage is either to: or cc: EXPR
~Ddeleted messages
~d [MIN]-[MAX]messages with ``date-sent'' in a Date range
~Eexpired messages
~e EXPRmessage which contains EXPR in the ``Sender'' field
~Fflagged messages
~f USERmessages originating from USER
~gPGP signed messages
~GPGP encrypted messages
~h EXPRmessages which contain EXPR in the message header
~kmessage contains PGP key material
~i IDmessage which match ID in the ``Message-ID'' field
~L EXPRmessage is either originated or received by EXPR
~lmessage is addressed to a known mailing list
~m [MIN]-[MAX]message in the range MIN to MAX *)
~n [MIN]-[MAX]messages with a score in the range MIN to MAX *)
~Nnew messages
~Oold messages
~pmessage is addressed to you (consults $alternates)
~Pmessage is from you (consults $alternates)
~Qmessages which have been replied to
~Rread messages
~r [MIN]-[MAX]messages with ``date-received'' in a Date range
~Ssuperseded messages
~s SUBJECTmessages having SUBJECT in the ``Subject'' field.
~Ttagged messages
~t USERmessages addressed to USER
~Uunread messages
~vmessage is part of a collapsed thread.
~x EXPRmessages which contain EXPR in the `References' field
~y EXPRmessages which contain EXPR in the `X-Label' field
~z [MIN]-[MAX]messages with a size in the range MIN to MAX *)
~=duplicated messages (see $duplicate_threads)

10 Keybinding patterns

\ttab
<tab>tab
\rcarriage return
\nnewline
\eescape
<esc>escape
<up>up arrow
<down>down arrow
<left>left arrow
<right>right arrow
<pageup>Page Up
<pagedown>Page Down
<backspace>Backspace
<delete>Delete
<insert>Insert
<enter>Enter
<return>Return
<home>Home
<end>End
<space>Space bar
<f1>function key 1
<f10>function key 10

2009-06-03

LINUX VSFTPD

before run check module path in file /etc/pam.d/vsftpd
vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES

#xferlog_enable=YES #wlaczenie logowania
xferlog_std_format=NO
#xferlog_file=/var/log/vsftpd.log
vsftpd_log_file=/var/log/vsftpd.log
#log_ftp_protocol=YES

connect_from_port_20=YES

#idle_session_timeout=600
#data_connection_timeout=120
#nopriv_user=ftpsecure

ftpd_banner=Welcome to ftp server

chroot_local_user=YES
secure_chroot_dir=/usr/share/empty

# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/vsftpd.chroot_list

# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.

pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/vsftpd.user_list

#enable for standalone mode
listen=YES
tcp_wrappers=YES

2009-04-03

LINUX SCREEN

1 OS commands

screen -lssession list
screen -r [session]attach to active session
screen -xattach multiply users to active session
screen -dmS [session] [app]run app without start screen

2 Screen Commands

COMMANDDESCRIPTION
C-a ddeatach
C-a "window list
C-a wwindow list
C-a :number [0-9]change window nr
C-a Achange window name
C-a shift+nshow window nr
C-a cnew window
C-a kkill window
C-a [0-9]go to window nr
C-a [SPC]next window
C-a [BPC]previous window
C-a C-alast active window
C-a [ESC]turn on mode scrollback/copy
[SPC]start/stop buffer copy
C-a ]paste from buffer
C-a ?help
C-a :command line

3 .screenrc

startup_message off
deflogin off
defnonblock 5
termcapinfo xterm*|rxvt* 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
termcapinfo xterm*|rxvt* ti@:te@
#defbce "on"
vbell off
altscreen on
bindkey -k F1 prev
bindkey -k F2 next
bind ^v screen -t ROOT su -
hardstatus alwayslastline
hardstatus string '%{= KM}[ %{G}%H %{M}][%= %{c}%?%-Lw%?%{C}(%{C}%n*%f%t%{C})%{c}%?%+Lw%?%? %=%{M}][%{G} %c %{M}]'
defscrollback 1024
screen 0

2009-03-15

LINUX TCPDUMP

tcpdump -XXnve -i eth1 'arp [7]==2' -s0
#read data with header in ASCI and HEX - use option -XX, which 8-th byte in ARP header will be 2(DEC) - count from 0 to 7, means answer on ARP broadcast
tcpdump -XXnve -i eth1 'tcp [13]==18' -s 0
#read data as above, which 14th byte in TCP header:
18(DEC) = 12 (HEX) = 00010010(BIN) means set flags SYN and ACK, C|E|U|A|P|R|S|F where letters mean flags in bits code
0 0 0 1 0 1 1 0 means set flag ACK,RST,SYN - 22(DEC) and 16(HEX)

describe TCPDUMP output

ARP answer on  broadcast:
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
12:55:53.464953 00:c0:a8:fe:6f:f2 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 192.168.1.212 tell 192.168.1.24
0x0000:  ffff ffff ffff 00c0 a8fe 6ff2 0806 0001  ..........o.....
0x0010:  0800 0604 0001 00c0 a8fe 6ff2 c0a8 0118  ..........o.....
0x0020:  0000 0000 0000 c0a8 01d4 0000 0000 0000  ................
0x0030:  0000 0000 0000 0000 0000 0000            ............
Description in order:
1w/8k/1-4 means 1 row/8 column/position form 1 to 4:
1w/1k/1-...1w/3k/-4 destination MAC
1w/4k/1-...1w/6k/-4 source MAC
1w/7k/1-4  typ ramki: 0806 - ARP; 0800 - IP; 8035 - reverse ARP; 8137 - IPX
------------------------START IP protocol----------------------------------------------
1w/8k/1-4  device address type: 0001 - Ethernet
2w/1k/1-4  protocol address type: 0800 - IP
2w/2k/1-2  length device address in Btes
2e/2k/3-4  length proctocol address in Bytes
2w/3k/1-4  operation: 0001 - question; 0002 - answer
2w/4k/1-...2w/6k/-4 sender MAC
2w/7k/1-...2w/8k/-4 sender IP
3w/1k/1-...3w/3k/-4 recipient MAC
3w/4k/1-...3w/5k/-4 recipient IP

send 1 tcp packet with flags SYN,ACK,RST and data "ABC" which means 3 Bytes from file "wy" by hping3:
hping3 192.168.1.253 -S -A -R -E wy -d 3 -c 1
we receive:
ROUTER:/# tcpdump -XXnve -i eth1 'tcp [13]==22' -s0 and host 192.168.1.4
tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
13:30:10.508842 00:0c:76:e7:f1:d3 > 00:30:4f:23:b8:4e, ethertype IPv4 (0x0800), length 60: IP (tos 0x0, ttl  64, 
id 57585, offset 0, flags [none], length: 43) 192.168.1.4.2029 > 192.168.1.253.0: SR [tcp sum ok] 1842019365:1842019368(3) 
ack 2138831316 win 512 [RST ABC]
0x0000:  0030 4f23 b84e 000c 76e7 f1d3 0800 4500  .0O#.N..v.....E.
0x0010:  002b e0f1 0000 4006 158a c0a8 0104 c0a8  .+....@.........
0x0020:  01fd 07ed 0000 6dca fc25 7f7b f9d4 5016  ......m..%.{..P.
0x0030:  0200 ba09 0000 4142 4300 0000            ......ABC...
----------------------------------------------------------------------------------------
1w/1k/1-...1w/3k/-4 destination MAC
1w/4k/1-...1w/6k/-4 source MAC
1w/7k/1-4  typ ramki: 0806 - ARP; 0800 - IP; 8035 - reverse ARP; 8137 - IPX
------------------------START IP protocol----------------------------------------------
1w/8k/1   wersja protokoĊ‚u
1w/8k/2   header length in Bytes
1w/8k/3-4  TOS type
2w/1k/1-4  whole length hader plus data
2w/2k/1-4  datagram ID
2w/3k/1   fragmentation sign
2w/3k/2-4  shift
2w/4k/1-2  TTL field
2w/4k/3-4  protocol type: 06 - TCP; 17 - UDP; 01 - ICMP;
2w/5k/1-4  control sum header
2w/6k/1-...2w/7k/-4 sender IP
2w/8k/1-...3w/1k/-4 recipient IP
------------------------START TCP protocol---------------------------------------------
3w/2k/1-4  source port
3w/3k/1-4  destination port
3w/4k/1-...3w/5k/-4 output data order nr
3w/6k/1-...3w/7k/-4 input data order nr
3w/8k/1-2  header length
3w/8k/3-4  cody bits: 02 - SYN; 12 - SYN,ACK; 16 - SYN,ACK,RST
4w/1k/1-4  input data window
4w/2k/1-4  header control sum
4w/3k/1-4  pointer data
------------------------START data----------------------------------------------------
4w/4k/1-  dane 41,42,43 in ASCI means ABC