Thursday, January 28, 2016

analyzing and storing logs

Analyzing and storing logs:::

logfiles are maintained by rsyslog service::
/var/log directories contain a variety of log files:::

 all the log configuration are stored in the /etc/rsyslog.conf


Log file rotation::
by logrotate utility : when rotated logfiles are renamed by with an extension indicating the date on which it was rotated:
/var/log/messages file becomes /var/log/messages-20150126
rotated on January 26 2015
(logrotate man page)

analyze a syslog entry::
[root@localhost ~]# tail -f /var/log/secure
Jan 27 19:34:25 localhost gdm-launch-environment]: pam_unix(gdm-launch-environment:session): session opened for user gdm by (uid=0)
Jan 27 19:34:37 localhost polkitd[947]: Registered Authentication Agent for unix-session:c1 (system bus name :1.30 [gnome-shell --mod

send a syslog message with logger::(confusion))



Reviewing systemd journal entries:::
journalctl command shows the full system journal starting with the oldest log entry.

[root@localhost ~]# journalctl
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou

By default journalctl gives last 10 log entries
specifying we can get our desired: for example to get the last 5 entries:
[root@localhost ~]# journalctl -n 5
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Jan 27 20:20:01 localhost.localdomain systemd[1]: Starting Session 8 of
Jan 27 20:20:01 localhost.localdomain CROND[5166]: (root) CMD (/usr/lib
Jan 27 20:30:01 localhost.localdomain systemd[1]: Started Session 9 of
Jan 27 20:30:01 localhost.localdomain systemd[1]: Starting Session 9 of
Jan 27 20:30:01 localhost.localdomain CROND[5367]: (root) CMD (/usr/lib
lines 1-6/6 (END)

 also to log entry only those who have priority as err or above::
[root@localhost ~]# journalctl -p err
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Jan 27 19:33:23 localhost.localdomain kernel: sd 2:0:0:0: [sda] Assumin
Jan 27 19:33:36 localhost.localdomain systemd-udevd[760]: unable to mov
Jan 27 19:33:37 localhost.localdomain kernel: piix4_smbus 0000:00:07.3:
Jan 27 19:34:23 localhost.localdomain dhclient[2084]: receive_packet fa
Jan 27 19:34:28 localhost.localdomain dhclient[2084]: send_packet: Netw
Jan 27 19:34:28 localhost.localdomain dhclient[2084]: dhclient.c:2407:
Jan 27 19:34:32 localhost.localdomain pulseaudio[2916]: [alsa-source-ES

journalctl -f itself can displsy last 10 lines of the journal and even can display updated one.(replacement of use of tail)
 also we can use options like yesterday ,today tomorrow combined with either --since or --until

root@localhost ~]# journalctl --since yesterday
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou
Jan 27 19:33:21 localhost.localdomain kernel: Initializing

also we can use date in YYYY-MM-DD format and time in HH-MM-SS format
[root@localhost ~]# journalctl --since 2015-12-23
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou
Jan 27 19:33:21 localhost.localdomain systemd-journal[342]: Runtime jou
Jan 27 19:33:21 localhost.localdomain kernel: Initial

output the journal entries from 10 the february 2015 20:30:00 to 13th february 2015 12:00:00

[root@localhost ~]# journalctl --since "2015-02-10 20:30:00" --until "2015-02-13 12:00:00"

also we can view detail By::

[root@localhost ~]# journalctl -o verbose
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Wed 2016-01-27 20:
Wed 2016-01-27 19:33:21.697010 EST [s=d58dea757c3947e38eafaf5e1317364a;
    PRIORITY=6
    _TRANSPORT=driver
    MESSAGE=Runtime journal is using 8.0M (max allowed 91.2M, trying to
    MESSAGE_ID=ec387f577b844b8fa948f33cad9a75e6
    _PID=342
    _UID=0
    _GID=0
    _COMM=systemd-journal


Moreover we can access the particular process or event by using the options like::
_COMM the name of the command
_EXE the path to the execuatable for the process
_PID the PID of the process
_SYSTEM_UNIT the system unit that started the process.
 can also be used combinely or individually such option::

[root@localhost ~]# journalctl _SYSTEM_UNIT=sshd.service _PID=112

journalctl with priority warning::
[root@localhost ~]# journalctl -p warning
-- Logs begin at Wed 2016-01-27 19:33:21 EST, end at Thu 2016-01-28 00:
Jan 27 19:33:21 localhost.localdomain kernel: ACPI: RSDP 00000000000f6a
Jan 27 19:33:21 localhost.localdomain kernel: ACPI: XSDT 000000007feea6
Jan 27 19:33:21 localhost.localdomain kernel: ACPI: FACP 000000007fefee
Jan 27 19:33:21 localhost.localdomain kernel: ACPI: DSDT 000000007feec0


 Preserving the systemd journal::

store the journal permanently:

[root@localhost ~]# mkdir /var/log/journals
first of all a directory /var/log/journals is created.

[root@localhost ~]# chown root:systemd-journal /var/log/journals
change the ownership to root user and systemd-journal group for the file .

[root@localhost ~]# chmod 2755 /var/log/journals
then set the sticky bit so that every one can read and access but cannot delete the content.

[root@localhost ~]# kilall -USR1 systemd-journald
finally send the special USR1 signal as user root.

maintaining accurate time:::
timdatectl command
[root@localhost ~]# timedatectl
      Local time: Thu 2016-01-28 13:06:07 EST
  Universal time: Thu 2016-01-28 18:06:07 UTC
        RTC time: Thu 2016-01-28 18:06:07
       Time zone: America/New_York (EST, -0500)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2015-11-01 01:59:59 EDT
                  Sun 2015-11-01 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2016-03-13 01:59:59 EST
                  Sun 2016-03-13 03:00:00 EDT


[root@localhost ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara


tzselect  command is useful for identifying various timezones on the basis of countries or continents.
[root@localhost ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean

[root@localhost ~]# timedatectl set-time 9:00:00
Failed to set time: Automatic time synchronization is enabled

 to set the current date[root@localhost ~]# timedatectl set-ntp false
to disable the network provided time.
Now we can change the time settings
[root@localhost ~]# timedatectl set-time 9:00:00
[root@localhost ~]# timedatectl
      Local time: Thu 2016-01-28 09:00:06 MST
  Universal time: Thu 2016-01-28 16:00:06 UTC
        RTC time: Thu 2016-01-28 16:00:07
       Time zone: America/Phoenix (MST, -0700)
root@localhost ~]# timedatectl set-time 1:45:00
[root@localhost ~]# timedatectl
      Local time: Thu 2016-01-28 01:45:03 MST
  Universal time: Thu 2016-01-28 08:45:03 UTC
        RTC time: Thu 2016-01-28 08:45:04
       Time zone: America/Phoenix (MST, -0700)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a
[root@localhost ~]# timedatectl set-ntp True
[root@localhost ~]# timedatectl
      Local time: Thu 2016-01-28 11:46:24 MST
  Universal time: Thu 2016-01-28 18:46:24 UTC
        RTC time: Thu 2016-01-28 08:45:34
       Time zone: America/Phoenix (MST, -0700)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no



[root@localhost ~]# timedatectl set-ntp True
[root@localhost ~]# timedatectl
      Local time: Thu 2016-01-28 11:46:24 MST
  Universal time: Thu 2016-01-28 18:46:24 UTC
        RTC time: Thu 2016-01-28 08:45:34
       Time zone: America/Phoenix (MST, -0700)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

     NTP enabled: no
Now agai we can change the time and enable the NTP

NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

configuring and monitoring chronyd((confusion))  time source change garney esko kaam chaai.....

 for that we need to vi the given file first
[root@localhost ~]# vi /etc/chrony.conf
then change all the servers entries with the ip address of ur Pc as follows:

#use public servers fromthe pool.ntp.org project:::
server 192.168.122.1 iburst


Then restart the chronyd using systemctl command:

[root@localhost ~]# systemctl restart chronyd
 now finally we can verify if the modifications is done ::
[root@localhost ~]# chronyc sources -v
210 Number of sources = 2

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^? 192.168.122.1                 0   7     0   10y     +0ns[   +0ns] +/-    0ns
^* ec2-52-0-56-137.compute-1     2   6    17     6  -1851us[-1279us] +/-   60ms


 ###confusion related to adding directive through echo command and logger commadn
 for example::[root@localhost ~]# echo "authpriv.alert /var/log/auth-errors" > /etc/rsylog.d/auth-errors.conf


Thursday, January 21, 2016

RHL7 Configuring and securing openssh service::

Configuring and securing openssh service::


to connect to a remotehost as the current user:::
ssh 192.168.122.1

[root@localhost ~]# ssh 192.168.122.1(here current user is root,so we are logging as root in the remote host as well)
The authenticity of host '192.168.122.1 (192.168.122.1)' can't be established.
ECDSA key fingerprint is a1:48:e8:2b:14:09:43:19:be:44:31:eb:0a:65:7e:c8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.122.1' (ECDSA) to the list of known hosts.
root@192.168.122.1's password:
Last login: Thu Jan 21 11:02:35 2016

connect to a remote shell as a different user.. Now i am root here and i want to connect as ashok in the remotehsot, then:
ssh ashok@remotehost
[root@localhost ~]# ssh ashok@192.168.122.1
ashok@192.168.122.1's password:
Last login: Thu Jan 21 14:31:50 2016 from 192.168.122.1

 displaying and changing the hostname of remotehost
::::

[ashok@localhost ~]$ ssh ashok@192.168.122.1 hostname
ashok@192.168.122.1's password:
localhost.localdomain
[ashok@localhost ~]$ hostname ashok
hostname: you must be root to change the host name
[ashok@localhost ~]$ su -
Password:
Last login: Thu Jan 21 14:28:01 EST 2016 from 192.168.122.1 on pts/4
[root@localhost ~]# hostname remoteuser
[root@localhost ~]# hostname
remoteuser
[root@localhost ~]# su ashok
[ashok@remoteuser root]$ cd
[ashok@remoteuser ~]$ exit
exit
[root@localhost ~]# ssh ashok@192.168.122.1
ashok@192.168.122.1's password:
Last login: Thu Jan 21 14:39:44 2016
[ashok@remoteuser ~]$

SSH hostkeys:::

first time a user uses ssh to connect to particuylar server, it stores a public key  in the users ~/.ssh/known_hosts and durig each logging
it checks for that match of public key and only then allows the connection;

COnfiguring ssh key_based authentication::
  to connect to the remotehost, as we discussed earlier we need to match the public key however there is the secured way but we  dont need to type password to conect to the remotehost:
for that we need to use following commands::(this is called public key authentication)


first of all
[ashok@localhost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ashok/.ssh/id_rsa):
/home/ashok/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ashok/.ssh/id_rsa.
Your public key has been saved in /home/ashok/.ssh/id_rsa.pub.
The key fingerprint is:
12:8e:eb:23:bd:7c:26:18:58:d9:4e:db:35:19:d1:c6 ashok@remoteuser
The key's randomart image is:
+--[ RSA 2048]----+
|        .+       |
|        . E      |
|   o  .  +       |
|  o oo .+        |
| o o.oo.S.       |
|. . o...         |
|   +.            |
|  oo+ o          |
|   .+*           |
+-----------------+
[ashok@localhost ~]$ ssh-copy-id ashok@192.168.122.1
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ashok@192.168.122.1's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'ashok@192.168.122.1'"
and check to make sure that only the key(s) you wanted were added.

[ashok@localhost ~]$ ssh ashok@192.168.122.1
Last login: Thu Jan 21 16:10:14 2016( notice over here previously it used to ask for password but now it hasnot)
this is wha we can do with ssh key-gen to login to any remotehost that we have acces to


Costumizing ssh service configuration:::
resrticting ssh logins::
 first of we have to generate ssh keys on remotehost;


[ashok@localhost ~]$ ssh key-gen
after completing the middle steps of this command we need
ssh-copy-id remotehost( this will copy id to the remotehost)

[ashok@localhost ~]$ ssh-copy-id 192.168.122.1

after some steps of the above command try logging into the remotehost

[ashok@localhost ~]$ ssh ashok@192.168.122.1
Last login: Thu Jan 21 16:40:17 2016 from 192.168.122.1
 after logging in gain the root priviliges:;

[ashok@remoteuser ~]$ su -
Password:
Last login: Thu Jan 21 16:34:35 EST 2016 on pts/1
[root@remoteuser ~]#
 now configure ssh on remoteuser to prevent root logins::

[root@remoteuser ~]# vi /etc/ssh/sshd_config
permitrootlogin no

[root@remoteuser ~]# systemctl restart sshd

again to prevent passwordauthentication

root@remoteuser ~]$ vi /etc/ssh/sshd_config
 PasswordAuthentication no

[root@remoteuser ~
]# systemctl restart sshd
 now again try connecting as root to remotehost, thi type it denied without asking for password
however last time it asked for password( now it didnt because we added passwordauthentication no) in /etc/ssh/sshd_config..



Controlling services and DAEMONS::

for the kernel representation of system CPUs

[root@localhost ~]# grep "model name" /proc/cpuinfo
model name      : Pentium(R) Dual-Core  CPU      E5300  @ 2.60GHz



Controlling services and DAEMONS::

daemons are processes that wait or run in the background performing various tasks.

To view the status of a service::

systemctl status name.type

without type it will display the status of a service unit, if one exists
root@localhost ~]# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-01-21 09:47:09 EST; 3h 22min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 1535 (sshd)
   CGroup: /system.slice/sshd.service
           └─1535 /usr/sbin/sshd -D

Jan 21 09:47:09 localhost.localdomain systemd[1]: Started OpenSSH serve...
Jan 21 09:47:09 localhost.localdomain systemd[1]: Starting OpenSSH serv...
Jan 21 09:47:10 localhost.localdomain sshd[1535]: Server listening on 0...
Jan 21 09:47:10 localhost.localdomain sshd[1535]: Server listening on :...
Jan 21 09:59:42 localhost.localdomain sshd[4268]: Accepted password for...
Jan 21 11:01:34 localhost.localdomain sshd[6101]: Accepted password for...
Jan 21 12:22:57 localhost.localdomain sshd[8134]: Accepted password for...
Hint: Some lines were ellipsized, use -l to show in full.


to query the state of only service units::
systemctl --type=service

 to view if there are any failed or maintainence state::
systemctl status rngd.service -l ( -l option will show the long listing)

 alternate commands to check whether the particular command is active or not...

root@localhost ~]# systemctl is-active sshd( it shows whether its current state is active or not)
active
[root@localhost ~]# systemctl is-enabled sshd (it shows whether it was enabled at boot time or not)
enabled
 
to list all active state of all loaded units::

systemctl list-units --type=service
[root@localhost ~]# systemctl list-units --type=service
  UNIT                      LOAD   ACTIVE SUB     DESCRIPTION
  abrt-ccpp.service         loaded active exited  Install ABRT coredump ho
  abrt-oops.service         loaded active running ABRT kernel log watcher
  abrt-xorg.service         loaded active running ABRT Xorg log watcher
  abrtd.service             loaded active running ABRT Automated Bug Repor
  accounts-daemon.service   loaded active running Accounts Service
  alsa-state.service        loaded active running Manage Sound Card State
  atd.service               loaded active running Job spooling tools
  auditd.service            loaded active running Security Auditing Servic
  avahi-daemon.service      loaded active running Avahi mDNS/DNS-SD Stack
  blk-availability.service  loaded active exited  Availability of block de
  bluetooth.service         loaded active running Bluetooth service

if -all option is used (systemctl list-units --type=service --all) it even displays inactive units
 
TO list all socket units active or inactive in the system::
systemctl list-units --type=socket --all


To display if sshd is active without displaying all other status information::
systemctl is-active sshd
[root@localhost ~]# systemctl is-enabled sshd
enabled

Now if we have to display even other status information::
systemctl status sshd

 List the enabled and disabled states of all service units::
systemctl list-units --type=service --all
Unit dependcies::
services may have depencies on one another. For example if we have to stop printing services , we have to stop 
all three units related to that very unit that may be from other units

 masking services::
 if there are conflicting services installed and we dont want to open up tha conflicted service accidently we have to mask that 
service to /dev/null.
systemctl mask network
[root@localhost ~]# systemctl mask network
Created symlink from /etc/systemd/system/network.service to /dev/null.

Now the service cannot be opened manually as well as automatically



restarting a service will change its process id..
but reloading wont change any process id and no connections are interrupted

enabling any service will make it ready to start at system boot

Processes:::
parent process
child process
different process states::
R = task running
S = sleeping
D = sleeping (but interruptible)
K =task killable
T = task stopped
Z=exit zombie(a child process signals as its parents exits
.all resources except for the process identity (PID) are realeased
X= exit dead

listing processes:: ps -aux ( displays all processes with columns in which users will be
interested)

[ashok@localhost ~]$ ps -aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.3  0.3 126588  7384 ?        Ss   09:46   0:04 /usr/lib/syste
root          2  0.0  0.0      0     0 ?        S    09:46   0:00 [kthreadd]
root          3  0.0  0.0      0     0 ?        S    09:46   0:00 [ksoftirqd/0]
root          5  0.0  0.0      0     0 ?        S<   09:46   0:00 [kworker/0:0H]
root          6  0.0  0.0      0     0 ?        S    09:46   0:00 [kworker/u256:
root          7  0.0  0.0      0     0 ?        S    09:46   0:00 [migration/0]
root          8  0.0  0.0      0     0 ?        S    09:46   0:00 [rcu_bh]
root          9  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/0]
root         10  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/1]
root         11  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/2]
root         12  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/3]
root         13  0.0  0.0      0     0 ?        S    09:46   0:00 [rcuob/4]

 ps -lax gives more technical detail and more faster coz it doesnt
provide username( ps -ef is also a unix command to look all processes)

[ashok@localhost ~]$ ps -lax
F   UID    PID   PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0      1      0  20   0 126588  7384 ep_pol Ss   ?          0:04 /usr/lib/
1     0      2      0  20   0      0     0 kthrea S    ?          0:00 [kthreadd
1     0      3      2  20   0      0     0 smpboo S    ?          0:00 [ksoftirq
1     0      6      2  20   0      0     0 worker S    ?


       0:00 [kwo


Controlling jobs::
 running jobs in the background::

[ashok@localhost ~]$ sleep 1000 &
[1] 4998
 checking if jobs is running:
[ashok@localhost ~]$ jobs
[1]+  Running                 sleep 1000 &

bringing job in the foreground:;
[ashok@localhost ~]$ fg %1
sleep 1000

To again send the job to background and send the suspend request
press Ctrl-z
[ashok@localhost ~]$ fg %1
sleep 1000
^Z
[1]+  Stopped                 sleep 1000

ps with option j displays job information including the command shell of each session
ashok@localhost ~]$ ps j
  PPID    PID   PGID    SID TTY       TPGID STAT   UID   TIME COMMAND
  4146   4150   4150   4150 pts/0      4150 Ss+   1000   0:00 /bin/bash
  4272   4274   4274   4274 pts/1      5174 Ss    1000   0:00 -bash
  4274   5165   5165   4274 pts/1      5174 T     1000   0:00 sleep 1000
  4274   5174   5174   4274 pts/1      5174 R+    1000   0:00ps j

 Killing processes::
 to list signals

[ashok@localhost ~]$ kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL       5) SIGTRAP
 6) SIGABRT      7) SIGBUS       8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

 we can use killall to send signal for more processes at once under
certain pattern.
even pkill is used to send signal to multiple processes at once
 pkill command_pattern
pkill -signal command_pattern
pkill -G GID command_pattern
pkill -t terminal_name -U UID command_pattern


pgrep -l -u username searches for all the processes associated with that username

[root@localhost ~]# pgrep -l -u ashok
3280 gnome-keyring-d
3323 gnome-session
3330 dbus-launch
3331 dbus-daemon
3396 gvfsd
3400 gvfsd-fuse
3475 ssh-agent
3491 at-spi-bus-laun
3495 dbus-daemon
3500 at-spi2-registr
3511 gnome-settin


To see all the process tree for the system or single user, we use pstree command
[root@localhost ~]# pstree -p ashok

at-spi-bus-laun(3491)─┬─dbus-daemon(3495)───{dbus-daemon}(3497)
                      ├─{at-spi-bus-laun}(3492)
                      ├─{at-spi-bus-laun}(3494)
                      └─{at-spi-bus-laun}(3496)
pkill -p 3491 will kill all the children they have created because
here the PPID is 3491 and parent is at-spi-bus-laun(3491)


Thursday, January 14, 2016

groupmod,usermod ,passwords(Red Hat 7)

groupmod uses:::
 groupmod -n newmane oldname

to modify existing groupids
groupmod -g 2000 ateam( suppose previously roup a ateam has agroup id of 1005 now it will be 2000)


usermod even helps change a group of auser::
usermod -g  newgroup username
(now it will assign the username to newgroup
 

adding a supplemental group to a user


usermod -aG newgroup username
(this will append a newgroup that is supplemental one for the username)


differences between groupmod and groupadd ??
 groupmod just changes the name and group id of a existing group whereas usermod can change the group of a existing group, append a supplemental group to any existing user..the examples can be seen above..




managing user passwords::
 passwords stored in /etc/shadow file

three parts in amodern password
     $1$gCj La2/Z$6 Pu0EK0AzfCj xj v2ho LOB/

1.. 1: The hashing algorithm .The number 1 indicates an MD5 hash. the number 6 appears when $HA-512 hash is used
2. gCjLa2/Z: The salt used to encrypt the hash.
3:6Pu0 EK0AzfCj x j v2ho LOB/: the encrypted hash

authconfig - - passalgo ::: a command that determines which is the appropriate setting for password protection in /etc/shadow file


Password aging::;
 The several options are as follows::
chage -d 0 username ::: will force a user to update on next login..
chage -l username :: will list a username current settings

chage -E yyyy-mmmm-DD will expire an account on specific day
  #nologin sheel (confusion)

Sunday, January 10, 2016

RHL7 adding users as sudoers

how to grant sudo privilege to new user names as 'mynewuser'


for that we need to carry out the following steps;

become root: su -
then type the command: visudo
search for the following  #allow root to run any command anywhere
add the following by inserting:

mynewuser ALL=(ALL) ALL
save and quit:wq

installing vmware

 how to install vmware on linux
 first of download vmare bundle on ur pc inside Downloads and follow the following steps;;


ashok@ashok:~$ sudo apt-get install build-essential linux-headers-`uname -r`
Reading package lists... Done
Building dependency tree    
Reading state information... Done
build-essential is already the newest version.
linux-headers-3.16.0-44-generic is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.


change your current directory to downloads and list all available over there



ashok@ashok:~$ cd /home/ashok/Downloads



ashok@ashok:~/Downloads$ ls -l
total 1642660
-rw-r----- 1 ashok ashok    241754 Oct  4 14:11 11696607_1596467153963786_4550855425001071167_o.jpg
-rw-r----- 1 ashok ashok    414803 Oct  4 14:10 11907155_1616732095270625_3006793256146796048_o.jpg
-rw-r----- 1 ashok ashok     59291 Nov 29 20:17 12311397_909014092528437_123997452_o.jpg
-rw-r----- 1 ashok ashok     57180 Oct  7 22:47 18373101441-459318804-registration.pdf
-rw-rw-r-- 1 ashok ashok      4852 Nov  5 10:42 1920330_1081231035228105_976989325251166712_n.jpg
-rw-rw-r-- 1 ashok ashok      8639 Nov 22 19:47 2(1).py
-rw-r----- 1 ashok ashok     55929 Sep 22 17:25 267549_108259742603880_7115829_n.jpg
-rw-rw-r-- 1 ashok ashok      8639 Nov 22 19:15 2.py
-rw-r----- 1 ashok ashok     38579 Sep 22 17:28 483511_357713057658546_777917237_n.jpg
-rw-r----- 1 ashok ashok     46951 Sep 22 17:26 560583_341516452611540_36203639_n.jpg
-rw------- 1 ashok ashok    136287 Sep 23 10:28 ACFrOgCca7kki9pxYYoWEC9tt4wb3yBsCYWQxgdvlWhfmRS9tVp9IwabFONpoziLEUK3blkFohOE2AlkyGpB2S8rrB-srsZj2K5AQLTnr3BdQj8YYRxh9M_KdHOmgpU=_print=true&nonce=pn31j11aabh4k&user=12749395014731097935&hash=hflelu3ego4dl7jak1n25q2p74p41113.pdf
-rw-r----- 1 ashok ashok      4368 Oct 25 10:15 adobe-release-i386-1.0-1.noarch.rpm
-rw-r----- 1 ashok ashok    155342 Jan  9 23:31 A Freshman's Guide to Tech Internships.pdf
-rw-r----- 1 ashok ashok      8029 Oct 13 22:28 AfricanStudiesSecondExamDefinition.docx
-rw-r----- 1 ashok ashok    135603 Oct 13 20:56 African-Studies-_-Second-Exam-Definition.pdf.docx
-rw-rw-r-- 1 ashok ashok     28820 Nov 17 10:37 article_clippings.zip
-rw-r----- 1 ashok ashok     13395 Sep 18 21:37 ashok essay.docx
-rw-rw-r-- 1 ashok ashok      6244 Dec 13 20:01 Ashok_hangman2(1).py
-rw-rw-r-- 1 ashok ashok      6244 Dec 13 20:02 Ashok_hangman2(2).py
-rw-rw-r-- 1 ashok ashok      6244 Dec 13 20:03 Ashok_hangman2(3).py
-rw-rw-r-- 1 ashok ashok      6244 Dec 13 19:58 Ashok_hangman2.py
-rw-rw-r-- 1 ashok ashok      1514 Nov 22 19:17 ashok.py
-rw-r----- 1 ashok ashok     18270 Nov 29 19:19 Ashok submission.docx
-rw-r----- 1 ashok ashok 666894336 Sep 24 20:46 CentOS-7-x86_64-Minimal-1503-01.iso
-rw-r----- 1 ashok ashok         0 Oct 21 21:52 computer science homework
-rw-r----- 1 ashok ashok      9409 Sep 23 22:07 CopyofDay10PracticeExamforSept29thTest.docx
-rw-r----- 1 ashok ashok  20565248 Jan  9 23:34 Day 01 lecture- What is CS-.pptx
-rw-r----- 1 ashok ashok    687650 Jan  9 23:34 Day 02 lecture- Programs, programming, and Python Slides.pptx
-rw-r----- 1 ashok ashok     37874 Oct  7 20:04 doc.pdf
-rw-r----- 1 ashok ashok     14814 Oct  5 21:52 EGPP CareerAssignment.docx
-rw-r----- 1 ashok ashok     86528 Sep 30 07:33 ENGW 104 Syllabus (Fall 2015) Section 7 (1).doc
-rw-r----- 1 ashok ashok     86528 Oct  6 22:45 ENGW 104 Syllabus (Fall 2015) Section 7 (2).doc
-rw-r----- 1 ashok ashok     86528 Oct  6 22:46 ENGW 104 Syllabus (Fall 2015) Section 7 (3).doc
-rw-r----- 1 ashok ashok     86528 Oct  6 22:51 ENGW 104 Syllabus (Fall 2015) Section 7 (4).doc
-rw-r----- 1 ashok ashok     86528 Oct  7 21:38 ENGW 104 Syllabus (Fall 2015) Section 7 (5).doc
-rw-r----- 1 ashok ashok     86528 Oct  7 21:47 ENGW 104 Syllabus (Fall 2015) Section 7 (6).doc
-rw-r----- 1 ashok ashok     86528 Oct 11 20:22 ENGW 104 Syllabus (Fall 2015) Section 7 (7).doc
-rw-r----- 1 ashok ashok     86528 Oct 25 12:12 ENGW 104 Syllabus (Fall 2015) Section 7 (8).doc
-rw-r----- 1 ashok ashok     86528 Oct 25 14:06 ENGW 104 Syllabus (Fall 2015) Section 7 (9).doc
-rw-r----- 1 ashok ashok     86528 Sep 30 07:33 ENGW 104 Syllabus (Fall 2015) Section 7.doc
-rw-r----- 1 ashok ashok     14615 Oct 12 14:28 Essay-10.docx
-rw-r----- 1 ashok ashok     14631 Oct 13 09:20 Essay-11 (1).docx
-rw-r----- 1 ashok ashok     14631 Oct 12 14:28 Essay-11.docx
-rw-r----- 1 ashok ashok     14207 Oct 13 09:20 Essay-12 (1).docx
-rw-r----- 1 ashok ashok     14207 Oct 12 14:28 Essay-12.docx
-rw-r----- 1 ashok ashok     14574 Oct 13 09:21 Essay-13 (1).docx
-rw-r----- 1 ashok ashok     14574 Oct 12 14:28 Essay-13.docx
-rw-r----- 1 ashok ashok      8736 Oct 13 00:40 Essay-14.docx
-rw-r----- 1 ashok ashok     13073 Sep 18 21:21 Essay #1.docx
-rw-r----- 1 ashok ashok     14990 Oct 12 09:37 Essay-1.docx
-rw-r----- 1 ashok ashok     14588 Oct 12 14:28 Essay-2 (1).docx
-rw-r----- 1 ashok ashok     14588 Oct 13 09:21 Essay-2 (2).docx
-rw-r----- 1 ashok ashok     14588 Oct 12 11:31 Essay-2.docx
-rw-r----- 1 ashok ashok     17545 Oct 12 14:28 Essay-3.docx
-rw-rw-r-- 1 ashok ashok    230126 Nov 16 10:04 essay 3 draft.docx
-rw-r----- 1 ashok ashok     15116 Oct 12 14:28 Essay-4.docx
-rw-r----- 1 ashok ashok     15026 Oct 12 14:28 Essay-5.docx
-rw-r----- 1 ashok ashok     15731 Oct 12 14:28 Essay-6.docx
-rw-r----- 1 ashok ashok     16403 Oct 12 14:28 Essay-7 (1).docx
-rw-r----- 1 ashok ashok     16403 Oct 12 14:28 Essay-7.docx
-rw-r----- 1 ashok ashok     14075 Oct 12 14:28 Essay-9.docx
-rw-rw-r-- 1 ashok ashok      9531 Nov 10 23:00 final resume.docx
-rw-rw-r-- 1 ashok ashok      6533 Nov 10 22:52 google essay.docx
-rw-rw-r-- 1 ashok ashok     13189 Dec  7 00:06 hangman2final.py
-rw-rw-r-- 1 ashok ashok      3004 Dec  6 21:42 hangman4.py
-rw-rw-r-- 1 ashok ashok     58003 Dec  5 19:52 hangman_english_words.txt
-rw-rw-r-- 1 ashok ashok     58003 Dec  5 19:52 hangman_english_words.txt~
drwxrwxr-x 4 ashok ashok      4096 Sep  5 19:41 install_flash_player_11_linux.x86_64
-rw-rw-r-- 1 ashok ashok   7266504 Sep  5 19:41 install_flash_player_11_linux.x86_64.tar.gz
-rw-r----- 1 ashok ashok   9911233 Oct 20 09:49 Learning_Python_-_Mark_Lutz (1).pdf
-rw-r----- 1 ashok ashok   5035772 Oct 20 08:44 Learning_Python_-_Mark_Lutz.epub
-rw-r----- 1 ashok ashok   9911233 Oct 20 08:44 Learning_Python_-_Mark_Lutz.pdf
drwxrwxr-x 3 ashok ashok     12288 Sep 12 13:07 mobile
-rw-rw-r-- 1 ashok ashok      6098 Dec  6 19:58 my project 2(1).py
-rw-rw-r-- 1 ashok ashok      5467 Dec  6 21:09 My project 2 of python.py
-rw-rw-r-- 1 ashok ashok      5468 Dec  6 21:09 My project 2 of python.py~
-rw-rw-r-- 1 ashok ashok      6098 Dec  6 19:46 my project 2.py
-rw-r----- 1 ashok ashok     70144 Sep  6 12:08 occ_15-1122.xls
-rw-r----- 1 ashok ashok     49366 Oct  7 20:28 out.pdf
-rw-r----- 1 ashok ashok      8924 Sep 17 10:18 paperratergffdhyh.docx
-rw-rw-r-- 1 ashok ashok      3132 Dec  6 23:05 part2.py
-rw-rw-r-- 1 ashok ashok      3187 Dec  5 15:39 project 1 cs(1).py
-rw-rw-r-- 1 ashok ashok      3187 Dec 13 19:59 project 1 cs(2).py
-rw-rw-r-- 1 ashok ashok      3187 Nov 22 22:12 project 1 cs.py
-rw-r----- 1 ashok ashok   1948323 Jan  9 19:50 putty-0.66 (1).tar.gz
-rw-r----- 1 ashok ashok   1948323 Jan  9 19:50 putty-0.66.tar.gz
-rw-r----- 1 ashok ashok    524288 Jan  9 22:22 putty.exe
-rw-r----- 1 ashok ashok     16168 Oct  6 08:55 Resume.docx
-rw-r----- 1 ashok ashok   7865872 Jan  9 22:35 RH134-RHEL7(1) (1).pdf
-rw-r----- 1 ashok ashok   7865872 Jan  9 19:20 RH134-RHEL7(1).pdf
-rw-r----- 1 ashok ashok   5438245 Sep  5 17:27 Shell Programming in 24 Hours.pdf
-rw-r----- 1 ashok ashok    178159 Sep 21 08:35 Solutions to 156 sample Test 1 Fall 2015 Correct File.pdf
-rw-rw-r-- 1 ashok ashok     32164 Sep  5 19:47 Supp Syll 2015.docx
-rw-r----- 1 ashok ashok 221594545 Sep  5 20:54 The Seagull Handbook, 2nd Edition.pdf
-rw-r----- 1 ashok ashok   1193988 Sep  5 20:51 The Word_ Black Writers Talk Ab - Marita Golden.pdf
-rw-rw-r-- 1 ashok ashok      5481 Sep  6 16:01 Untitled 1.docx
-rw-r----- 1 ashok ashok  63279710 Sep 24 20:18 virtualbox-5.0_5.0.4-102546-Ubuntu-trusty_amd64.deb
-rw-r----- 1 ashok ashok 138848126 Jan 10 11:41 VMware-Player-12.1.0-3272444.x86_64 (1).bundle
-rw-r----- 1 ashok ashok 138848126 Jan 10 00:43 VMware-Player-12.1.0-3272444.x86_64.bundle

select the one which we have to install and follow the following command:;


ashok@ashok:~/Downloads$ gksudo bash ./VMware-Player-12.1.0-3272444.x86_64.bundle

 this helps you to get the graphical interface and one can follow their step to carry out the installation process;






Thursday, January 7, 2016

history to practice for RHEL7 book 2(personal)

  812  date
  813  grep '^Jan *4 2[123]' /root
  814  grep '^Jan *4 2[123]' door.log
  815  pwd
  816  grep '^Jan *4 2[123]' door.log
  817  grep ^door
  818  mkdir logsss
  819  cp door.log logsss
  820  ls -lr logsss
  821  date
  822  grep '^Jan *4 2[234]*' /logsss/door.log
  823  which door.log
  824  cd logsss
  825  pwd
  826  grep '^Jan *4 2[234]*' /root/logsss/door.log
  827  $!
  828  $?
  829  cd
  830  man grep
  831  cat >>ashok123
  832  date
  833  ls -l | grep -i '* jan 4 23:*"
  834  ls -l | grep -i '* jan 4 23:*'
  835  ls -l
  836  ls -l | grep -i '* jan 4 23:13*' ashok123
  837  ls -l | grep -i '* jan 4 23:13*' ashok123 |cat
  838  vim /etc/hosts
  839  cd
  840  exit
  841  vim /etc/mod
  842  vim /etc/motd
  843  ssh ashok@localhost
  844  ssh localhost
  845  ssh ashok@localhost
  846  vim /etc/motd
  847  ssh ashok@localhost
  848  vim /etc/motl
  849  vim /etc/motd
  850  ssh ashok@localhost
  851  ping 192.168.10.110
  852  cat usr/shr/share/doc/ sos-3.2
  853  cd usr/shr/share
  854  cd /usr
  855  ls -l
  856  cd local
  857  ls -l
  858  cd share
  859  ls
  860  ls -l
  861  su ashok
  862  yum install python
  863  fdisk -l
  864  fdisk /dev/sdb
  865  df -h
  866  blkid /dev/sdb1
  867  mount  UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" /mnt
  868  cd/mnt
  869  cd /mnt
  870  ls
  871  mkdir practice
  872  ls
  873  touch i am practicing hard
  874  ls -ltr
  875  pwd
  876  cd /
  877  df -h /mnt
  878  unmount /mnt
  879  umount /mnt
  880  df -h /mnt
  881  cd /mnt
  882  ls
  883  ls -l
  884  cd
  885  mount /dev/mnt/sdb1 /mnt
  886  cd /mnt
  887  ls -l
  888  blkid /dev/mnt/sdb1 /mnt
  889  blkid /dev/sdb1 /mnt
  890  mount /dev/sdb1 /mnt
  891  cd mount
  892  cd /mnt
  893  ls -l
  894  fdisk
  895  umount  /dev/sdb1
  896  cd
  897  umount /dev/sdb1
  898  blkid /dev/sdb2
  899  atq
  900  at -l
  901  at -c
  902  mkdir home/my job
  903  mkdir home/myjob
  904  mkdir /home/myfile
  905  echo "date > /home/myfile | at now +3min
  906  echo "date > /home/myfile" | at now +3min
  907  atq
  908  at -c 1
  909  atq
  910  while [$atq | wc -l ) -gt 0];do sleep 1; done
  911  echo 'date > /home/myfile' | at now +3min
  912  while [$(atq | wc -l) -gt 0];do sleep 1; done
  913   while [$(atq | wc -l) -gt 0]; do sleep 1; done
  914   while [ $(atq | wc -l) -gt 0 ]; do sleep 1; done
  915  cat myfile
  916  pwd
  917  ls -ltr
  918  more anaconda-ks.cfg
  919  mount 192.168.10.110:/home/users /mnt
  920  ping 192.168.10.110
  921  touch best.$$
  922  ld -ltr
  923  ls -ltr
  924  echo "date > /var/tmp/myjob.txt" | at now +3min
  925  atq
  926  date
  927  ls -l /var/tmp/myjob.txt
  928  date
  929  atq
  930  atq | wc -l
  931  date
  932  at 19.45 echo hello
  933  at 19:45
  934  atq
  935  date
  936  at 19:45
  937  date
  938  at 19:48
  939  ls -l /var/tmp/myfile.2
  940  atq
  941  date
  942  ls -l /var/tmp/myfile.2
  943  crontab -eu ashok
  944  crontab -lu ashok
  945  ls -l /var/tmp/myhello.txxt
  946  date
  947  crontab -eu ashok
  948  ls -l /var/tmp/myhello.txxt
  949  crontab -lu ashok
  950  date
  951  ls -l /var/tmp/myhello.txxt
  952  crontab -lu ashok
  953  ls -l /var/tmp/myhello.txxt
  954  more /var/tmp/myhello.txxt
  955  crontab -lu ashok
  956  su - ashok
  957  more /etc/cron.d/sysstat
  958  sar
  959  df -h
  960  tmpwatch
  961  yum search tmpwatch
  962  ls -l /etc/*release*
  963  more /etc/os-release
  964  yum clean all
  965  ls -l /usr/lib/tmpfiles.d/*.conf
  966  more /usr/lib/tmpfiles.d/tmp.conf
  967  systemd-tmpfiles
  968  man 5 tmpfiles
  969  man tmpfiles
  970  yum search tmpfiles.
  971  man tmpfiles.d
  972  ps -ef | more
  973  top
  974  df -h
  975  ps -ef| more
  976  man ps
  977  ps -ef |more
  978  ps axo pid,comm,nice,time --sort=nice
  979  ps axo pid,comm,nice,time --sort=nice | more
  980  ps axo pid,comm,nice,time,cls --sort=nice | more
  981  pwd
  982  time du -sh *
  983  nice -n 15 time du -sh *
  984  nice -n 15 firefox
  985  top
  986  su - ashok
  987  ps -ef| grep 18729
  988  top
  989  ps axo pid,comm,nice --sort=nice
  990  ps axo pid,comm,nice --sort=nice | grep 18729
  991  renice -n -15 18729
  992  ps axo pid,comm,nice --sort=nice | grep 18729
  993  cat /proc/cpuinfo | grep -i processor
  994  grep -c '^processor' /proc/cpuinfo
  995  grep -i processor /proc/cpuinfo
  996  cd /home/ashok/lab2
  997  ls -l
  998  getfacl bestfile
  999  su - ashok
 1000  su  - kamal
 1001  yum install cifs-utils sambaclient
 1002* yum install -y smb-client
 1003  yum install -ysamba-client
 1004  yum install -y samba-client
 1005  smbclient -L //192.168.10.2
 1006  mount -t cifs -u ashok //192.168.10.2/Users/suvi/Desktop/ashok /mnt
 1007  mount -t cifs -o ashok //192.168.10.2/Users/suvi/Desktop/ashok /mnt
 1008  mount -t cifs //192.168.10.2/Users/suvi/Desktop/ashok /mnt
 1009  df -h /mnt
 1010  cd /mnt
 1011  ls
 1012  mkdir test
 1013  mkdir best
 1014  touch creating files here
 1015  mkdir /cifsshare
 1016  mount -t cifs -o username=ashok //192.168.10.2/Users/suvi/Desktop/ashok /cifsshare
 1017  ls -ld /cifsshare
 1018  su - ashok
 1019  chmod g+w /cifsshare
 1020  su - ashok
 1021  chmod o+w /cifsshare
 1022  su - ashok
 1023  mount -o remount /cifsshare/
 1024  su - ashok
 1025  chmod -R 775 /cifsshare/
 1026  ls -ld /cifsshare/
 1027  history
[root@private mnt]#

Wednesday, January 6, 2016

A python list interview question



interview preparation questions:::

def extendlist(val,list=[]):
list.append(val)
return list
list1 = extendlist(10)
list2 = extendlist(123,[])
list3 = extendlist('a')
print "list1 = %s" % list1
print 'list2 = %s" % list2
print "list3 = %s' % lsit3


hint prepared by myself::;
%s means a place holder that formats values into strings; for example::
name =raw_input("who are you?")
print " hello %s" % (name)
here %s tokens allows to insert and ( potentially format) a string.Notice that the %s token is replace by whatever i pass to the string after % symbol.
"Hello %s, my name is %s" % ('john', 'mike') # Hello john, my name is mike".
 for integer %d is used instead of %s.


the output fort this question is
list1 = [10,'a']
list2 = [123]
list3 = [10,'a']
the output may not be the one we used to get on regular way but it is quite different because the argument is not set to default value of [] each time extendlist is called
however what actually happens is that the new default list is created
only once when the function is defined and the that same list is then  then used subsquently whenever extendlist is invoked without a list argument being specified. This is because expressions in default arguments are calculated when the functions is defined ,not when it's called.
source:http://www.toptal.com/python/interview-questions

Tuesday, January 5, 2016

yum repo

[root@ashok yum.repos.d]# cat /tmp/a | awk '{$1=""; print $0}'
 rpm -ivh httpd-2.4.6-40.el7.centos.x86_64.rpm
 rpm -ih httpd-2.4.6-40.el7.centos.x86_64.rpm
 rpm -i httpd-2.4.6-40.el7.centos.x86_64.rpm
 ls -l bind*
 rpm -ivh bind-9.9.4-29.el7.x86_64.rpm
 rpm -ivh bind-libs-9.9.4-29.el7.x86_64.rpm
 yum search bind
 yum clean all
 yum repolist
 pwd
 cd /etc/yum.repos.d/
 ls
 cat CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo kern.repo
 clear
 ls
 vi kern.repo
 yum repolist
 yum search bind
 ls
 mv CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo kern.repo
 mv kern.repo kern.repo.oldie
 yum repolist
 yum search bind
 yum search bind | more
 yum search bind.x86_64
 yum install bind
 pwd
 cd -
 ls -l httpd-tools-2.4.6-40.el7.centos.x86_64.rpm
 more /boot/grub2/grub.cfg
 ls -l /etc/grub2.cfg
 more ../boot/grub2/grub.cfg
 more /boot/grub2/grub.cfg
 more /etc/yum.conf
 pwd
 ls
 cd -
 ls
 more CentOS-Base.repo
 yum repolist
 yum list yum*
 yum list httpd
 yum list bind
 yum list installed
 yum list installed | wc -l
 yum grouplist
 yum list 'http*'
 yum list 'http'
 yum list http
 yum list httpd
 yum search all 'web server'
 yum info httpd
 yum provides /var/named
 yum provides /var/www/html/
 yum update httpd
 yum list kernel
 uname -r
 uname -a
 yum group list
 yum group info "identiry management server"
 yum group info "identiry Management Server"
 yum group info "identity Management Server"
 yum group install "Infiniband support"
 yum history
 history
 yum.repos.d]#

big o notation python

def print_all_numbers_then_all_pair_sums(list_of_numbers):

    print "these are the numbers:"
    for number in list_of_numbers:  #here n is the big o notation
        print number

    print "and these are their sums:"
    for first_number in list_of_numbers:     # here n^2 is the big o notation
        for second_number in list_of_numbers:
            print first_number + second_number


#Here our runtime is O(n + n^2)   which we call O(n^2).Even if it was O(n^2 + 100n), it would still be O(n^2).

talking about worst case:
 source :://www.interviewcake.com/article/python/big-o-notation-time-and-space-complexity
def contains(haystack,needle):
 #does the haystack contain the needle?
for item in haystacK:
  if item==needle:
return True
return False
here we might have 100 items  in our haystack , but the first item might be the needle , in which case we would return in just 1 iteration of our loop
in general way we'd say this is O(n) runtime and the worst case parrt would be implied.But to be more specific we could say  this is worst case O(n) and the best case O(1) rutime. For some algorithms we can also make rigorous statements about the "average case" runtime


space complexity: the final frontier:
sometimes we want to optimize for using less memory instead of ( or in addition) using less time.Talking about the memory cost ( or "space complexity") is very similiar to talking about time cost. We simply look at the total size ( relative to the size of the input) of any new variables we are allocating
 the function takes 0(1) space ( we aren't allocating any new variable)

def say_hi_n_times(n):
for time in range(n):
print "hi"

the function takes O(n) space(the size of hi_list scales with the size of the input):

now the following function takes O(n) space ( the size of the hi_list scales with the size of the input):
def list_of_hi_n_times(n):
hi_list=[]

for time in range(n):
hi.list.append('hi')
return hi_list
usually when we talk about space complexity we are talking about additional space:

we dont include space taken up by the inputs.For eg: this function takes constant space even though the input has n items:

def get_largest_item(list_of_items):
largest=0
for item i list_of_items:
if item > largest:
return largest



Big O anaylis is awesome except when it is not

You should make a habit of thinking about the time and space complexibility  of algorithms as you design them. Before long this'll become second nature ,allowing you to see optimizations and potential performances issues right away



source :://www.interviewcake.com/article/python/big-o-notation-time-and-space-complexity




Monday, January 4, 2016

VIM EDITOR RHEL7

editing in vi

from command mode to insert mode::
i = switch to insert mode and start inserting before the current position

a = switch to insert mode and start inserting afer the current position
A =move the cursor end of the current line switch to insert mode
I = switch to the end of the line nd  also inser mode
O= open a new line above the current one and switch to insert mode
o = open a new line below the current one and switch to insert mode


h = cursor left one position
l = cursor right one position
j =cursor one down position
k = cursor one line up
^ = move to the beginning of the current line
$ = move to the end of the current line
gg = move to the first line of the document
G = move to the last line of the document
w = move cursor to the beginning of next word ( incudes punctuation)
W= move cursor to the beginning of next word( escapes punctuation)
b= move cursor to the beginning of previous word ( includes punctuation)
B = move cursor to the beginning of previous word ( doesnt include punctuation as a word)
( = move cursor to the beginning of previous/current  sentence
) = move cursor to the beginning of next sentence
{ = move cursor to the beginning of current/previous paragraph
} = move cursor to the beginning of the next paragraph
x = to delete the character where cursor is placed
X = to delete the one character ahead of cursor
R = to replace the entire word
r = just to replace a single character
cw = to change from the current cursor position to the end of the file
cc = replace the entire line ( multiples lines if prefixed with the number)

rhel 7 grep command use

`[ashok@private ~]$ cat >dogs
cat
dog
concatenate
dogma
category
educated
[ashok@private ~]$ greo -i cat
bash: greo: command not found...
[ashok@private ~]$ grep -i cat
[ashok@private ~]$ grep -i 'cat'
^C
[ashok@private ~]$ grep -i 'cat' dogs
cat
concatenate
category
educated
[ashok@private ~]$ grep -iv cat dogs
dog
dogma
[ashok@private ~]$ grep -v ^[#] dogs
cat
dog
concatenate
dogma
category
educated
[ashok@private ~]$ grep -e 'cat' -e
]grep: option requires an argument -- 'e'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
[ashok@private ~]$ grep -e 'cat' -e 'dogs' dogs
cat
concatenate
category
educated
[ashok@private ~]$

Sunday, January 3, 2016

RHEL 7 networking examples

1. List all available interface on the system

[root@ashok ~]# nmcli connection show
- only to show active ones
[root@ashok ~]# nmcli connection show -active
NAME                UUID                                  TYPE            DEVICE
virbr0-nic          e9279275-54b8-48ef-a756-d4d714bcd5ac  generic         virbr0-nic
virbr0              b7af90bc-8003-49df-bf58-4180828be0fd  bridge          virbr0
Wired connection 2  e3d708dc-aefd-41ea-96d2-81bdd0d307b7  802-3-ethernet  ens37
Wired connection 1  8b3b2e8a-1e5d-4982-93d0-77f7fe4eba6a  802-3-ethernet  ens38
default             4f8fe83d-df38-4441-83ae-0d400f76c43d  802-3-ethernet  ens33

- list all configuration setting for the interace
[root@ashok ~]# nmcli con show "Wired connection 1"
connection.id:                          Wired connection 1
connection.uuid:                        8b3b2e8a-1e5d-4982-93d0-77f7fe4eba6a
connection.interface-name:              --
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes

- [root@ashok ~]# nmcli dev status
DEVICE      TYPE      STATE      CONNECTION
virbr0      bridge    connected  virbr0
ens33       ethernet  connected  default
ens37       ethernet  connected  Wired connection 2
ens38       ethernet  connected  Wired connection 1
virbr0-nic  tap       connected  virbr0-nic
lo          loopback  unmanaged  --

- display device status
[root@ashok ~]# nmcli dev show ens38
GENERAL.DEVICE:                         ens38
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:0C:29:80:C1:E6
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     Wired connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         192.168.10.17/24
IP4.GATEWAY:                            192.168.10.1
IP4.DNS[1]:                             192.168.10.1
IP6.ADDRESS[1]:                         fe80::20c:29ff:fe80:c1e6/64
IP6.GATEWAY:
[root@ashok ~]#



2. Assign static ip/gateway/dns on one of the interface
- adding ip/gateway
[root@ashok ~]# nmcli con add con-name eth-ens38 ifname ens38 type ethernet ip4 192.168.10.220/24 gw4 192.168.10.1
Connection 'eth-ens38' (23d86e57-2fae-480f-8015-4ea7a8539812) successfully added.
[root@ashok ~]#

- adding nameserver
[root@ashok ~]# nmcli con mod "eth-ens38" ipv4.dns 192.168.10.110


3. Bring up the interface.

- list connections on the system
[root@ashok ~]# nmcli connection show
NAME                UUID                                  TYPE            DEVICE
eth-ens38           23d86e57-2fae-480f-8015-4ea7a8539812  802-3-ethernet  --
Wired connection 1  8b3b2e8a-1e5d-4982-93d0-77f7fe4eba6a  802-3-ethernet  ens38
15dd-442e-bc69-25c5bf2c1b6b  802-3-ethernet  --

- bring up the interface
[root@ashok ~]# nmcli con up eth-ens38

- list the active interface
[root@ashok ~]# nmcli con show --active
NAME                UUID                                  TYPE            DEVICE
eth-ens38           23d86e57-2fae-480f-8015-4ea7a8539812  802-3-ethernet  ens38

- verify the ip address

[root@ashok ~]# ip addr show ens38
4: ens38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:80:c1:e6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.220/24 brd 192.168.10.255 scope global ens38
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe80:c1e6/64 scope link
       valid_lft forever preferred_lft forever
[root@ashok ~]#


4. Reboot the system and verify that your assigned ip address is still available.

- upon rebooting the system, verify the ip address is available.

# ifconfig -a
# ip addr show

[root@ashok ~]# ip route
default via 192.168.10.1 dev ens33  proto static  metric 100
192.168.10.0/24 dev ens38  proto kernel  scope link  src 192.168.10.220  metric 102
[root@ashok ~]#A

[root@ashok ~]# ping -c 2 yahoo.com
PING yahoo.com (98.138.253.109) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=52 time=53.9 ms




adding disk on vmware RHEL7


1. add the disk on vmware

2. Scan the disk

[root@ashok ~]#  echo "- - -"> /sys/class/scsi_host/host0/scan
[root@ashok ~]#  echo "- - -"> /sys/class/scsi_host/host1/scan
[root@ashok ~]#  echo "- - -"> /sys/class/scsi_host/host2/scan
[root@ashok ~]# fdisk -l

[root@ashok ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bdad6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/mapper/centos-root: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 6983 MB, 6983516160 bytes, 13639680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@ashok ~]# fdisk /dev/sdb

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (411648-4194303, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-4194303, default 4194303): +200M
Partition 2 of type Linux and of size 200 MiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3):
First sector (821248-4194303, default 821248):
Using default value 821248
Last sector, +sectors or +size{K,M,G} (821248-4194303, default 4194303): +200M
Partition 3 of type Linux and of size 200 MiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc3e9fc2d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      411647      204800   83  Linux
/dev/sdb2          411648      821247      204800   83  Linux
/dev/sdb3          821248     1230847      204800   83  Linux

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e):
Using default response e
Selected partition 4
First sector (1230848-4194303, default 1230848):
Using default value 1230848
Last sector, +sectors or +size{K,M,G} (1230848-4194303, default 4194303):
Using default value 4194303
Partition 4 of type Extended and of size 1.4 GiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc3e9fc2d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      411647      204800   83  Linux
/dev/sdb2          411648      821247      204800   83  Linux
/dev/sdb3          821248     1230847      204800   83  Linux
/dev/sdb4         1230848     4194303     1481728    5  Extended

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (1232896-4194303, default 1232896):
Using default value 1232896
Last sector, +sectors or +size{K,M,G} (1232896-4194303, default 4194303): +200M
Partition 5 of type Linux and of size 200 MiB is set

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1644544-4194303, default 1644544):
Using default value 1644544
Last sector, +sectors or +size{K,M,G} (1644544-4194303, default 4194303): +200M
Partition 6 of type Linux and of size 200 MiB is set

Command (m for help): p

Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc3e9fc2d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      411647      204800   83  Linux
/dev/sdb2          411648      821247      204800   83  Linux
/dev/sdb3          821248     1230847      204800   83  Linux
/dev/sdb4         1230848     4194303     1481728    5  Extended
/dev/sdb5         1232896     1642495      204800   83  Linux
/dev/sdb6         1644544     2054143      204800   83  Linux

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ashok ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bdad6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/mapper/centos-root: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 6983 MB, 6983516160 bytes, 13639680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc3e9fc2d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      411647      204800   83  Linux
/dev/sdb2          411648      821247      204800   83  Linux
/dev/sdb3          821248     1230847      204800   83  Linux
/dev/sdb4         1230848     4194303     1481728    5  Extended
/dev/sdb5         1232896     1642495      204800   83  Linux
/dev/sdb6         1644544     2054143      204800   83  Linux
[root@ashok ~]# mkf
mkfifo       mkfontscale  mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfontdir    mkfs         mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@ashok ~]# mkfs
mkfs         mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
[root@ashok ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=12800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=51200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ashok ~]# blkid /dev/sdb1
/dev/sdb1: UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" TYPE="xfs"
[root@ashok ~]# mount UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" /mnt
[root@ashok ~]# cd /mnt
[root@ashok mnt]# ls
[root@ashok mnt]# mkdir newdir
[root@ashok mnt]# ls
newdir
[root@ashok mnt]# touch this is so cool and I am liking it
[root@ashok mnt]# ls -ltr
total 0
drwxr-xr-x. 2 root root 6 Jan  3 17:23 newdir
-rw-r--r--. 1 root root 0 Jan  3 17:23 this
-rw-r--r--. 1 root root 0 Jan  3 17:23 is
-rw-r--r--. 1 root root 0 Jan  3 17:23 so
-rw-r--r--. 1 root root 0 Jan  3 17:23 cool
-rw-r--r--. 1 root root 0 Jan  3 17:23 and
-rw-r--r--. 1 root root 0 Jan  3 17:23 liking
-rw-r--r--. 1 root root 0 Jan  3 17:23 I
-rw-r--r--. 1 root root 0 Jan  3 17:23 am
-rw-r--r--. 1 root root 0 Jan  3 17:23 it
[root@ashok mnt]# pwd
/mnt
[root@ashok mnt]# cd /
[root@ashok /]# df -h /mnt
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       197M   11M  187M   6% /mnt
[root@ashok /]# umount /mnt
[root@ashok /]# df -h /mnt
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   10G  3.7G  6.4G  37% /
[root@ashok /]# cd /mnt
[root@ashok mnt]# ls
[root@ashok mnt]# ls -l
total 0
[root@ashok mnt]# cd
[root@ashok ~]# mount UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" /mnt
[root@ashok ~]# cd /mnt
[root@ashok mnt]# ls
am  and  cool  I  is  it  liking  newdir  so  this
[root@ashok mnt]#





 894  find /home -user ashok
  895  find /home -group ashok
  896  grep ashok /etc/group
  897  find /home -group kamal
  898  find /home -group devi
  899  find / -user kamal -group devi
  900  find /home -perm -777
  901  find /home -perm -222
  902  ls -l /home/ashok/n1234 /home/ashok/aaaaa /home/andy/a
  903  find /home -perm -111
  904  ls -l /home/andy/.mozilla/extensions
  905  ls -ld /home/andy/.mozilla/extensions
  906  find /home -perm -777
  907  ls -l /home/ashok/.mozilla/firefox/qpi9jfhh.default/lock
  908  p
  909  mkdir /home/abc
  910  chmod 777 /home/abc
  911  find /home -perm -777
  912  pwd
  913  find /home -size 2M
  914  find /home -size 2M -exec ls -l {} \;
  915  find /home -size 2M -exec ls -lh {} \;
  916  grep 1000 /etc/group
  917  groupadd -g 1000 ashok1
  918  find /home -size 2M -exec ls -lh {} \;
  919  groupdel ashok1
  920  find /home -size 2M -exec ls -lh {} \;
  921  find /home -mtime -130
  922  find /home -mmin -130
  923  ls -l
  924  find . -type f -links +1
  925  pwd
  926  df -l
  927  fdisk -l
  928  fdisk
  929  fdisk -l
  930  lshw
  931   echo "- - -"> /sys/class/scsi_host/host0/scan
  932   echo "- - -"> /sys/class/scsi_host/host1/scan
  933   echo "- - -"> /sys/class/scsi_host/host2/scan
  934  fdisk -l
  935  fdisk
  936  fdisk -cu /dev/sdb
  937  fdisk /dev/sdb
  938  fdisk -l
  939  mkfs.xfs /dev/sdb1
  940  blkid /dev/sdb1
  941  mount UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" /mnt
  942  cd /mnt
  943  ls
  944  mkdir newdir
  945  ls
  946  touch this is so cool and I am liking it
  947  ls -ltr
  948  pwd
  949  cd /
  950  df -h /mnt
  951  umount /mnt
  952  df -h /mnt
  953  cd /mnt
  954  ls
  955  ls -l
  956  cd
  957  mount UUID="1f25b100-13bc-4f91-957a-4eea740bc9f1" /mnt
  958  cd /mnt
  959  ls
  960  history
[root@ashok mnt]#





3. create a partition