Monday, November 7, 2016

python class day1

class Employee:

def __init__(self,first,last,pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + '.' + last + "@company.com"

def fullname(self):
return('{} {}'.format(self.first, self.last))
emp_1 = Employee('Corey', 'Schafer' , 50000)
emp_2 = Employee('Test', 'User', 60000)


'''print(emp_1)
print(emp_2)

emp_1.first = "corey"
emp_1.email = "Test.User@gmail.com"

emp_2.first = "anderson"
emp_2.email = "nderson@gmail.com"'''

print(emp_1.email)
print(emp_2.email)
#print(emp_1.fullname())
print(Employee.fullname(emp_1))


output:
Corey.Schafer@company.com
Test.User@company.com
Corey Schafer
=> None   

Tuesday, February 9, 2016

RED HAT 7 Linux networking

Managing RED HAT ENTERPRISE LINUX NETWORKING

displaying ip addresses:
[ashok@localhost ~]$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:fd:cb:90 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic eno16777736
       valid_lft 85235sec preferred_lft 85235sec
    inet6 fd84:6375:8789:0:20c:29ff:fefd:cb90/64 scope global noprefixroute dynamic
       valid_lft 6865sec preferred_lft 3265sec
    inet6 fe80::20c:29ff:fefd:cb90/64 scope link
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 500
    link/ether 52:54:00:05:c1:9d brd ff:ff:ff:ff:ff:ff

IP command may also be used to show stastics about network performances:

[ashok@localhost ~]$ ip -s link show  eno16777736

2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 00:0c:29:fd:cb:90 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    247828     3430     0       0       0       0

 TO show ip routing information:
[ashok@localhost ~]$ ip route
default via 192.168.1.1 dev eno16777736  proto static  metric 100
192.168.1.0/24 dev eno16777736  proto kernel  scope link  src 192.168.1.101  metric 100
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1

To test connectivity::
[ashok@localhost ~]$ ping -c1 192.168.1.101
PING 192.168.1.101 (192.168.1.101) 56(84) bytes of data.
64 bytes from 192.168.1.101: icmp_seq=1 ttl=64 time=0.192 ms

--- 192.168.1.101 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.192/0.192/0.192/0.000 ms

[ashok@localhost ~]$ ss -ta
State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port
LISTEN     0      5      192.168.122.1:domain                *:*        
LISTEN     0      128     *:ssh                   *:*
LISTEN     0      128    127.0.0.1:ipp                   *:*            
LISTEN     0      100    127.0.0.1:smtp                  *:*            
ESTAB      0      64     192.168.1.101:ssh                  192.168.1.140:57710
LISTEN     0      128    :::ssh                  :::*
LISTEN     0      128       ::1:ipp                  :::*                
LISTEN     0      100       ::1:smtp                 :::*                



    TX: bytes  packets  errors  dropped carrier collsns
    51345      479      0       0       0       0



Configuring network information with NMCLI:

to list all connections,add and list only active connections and many more:



TO list all connection:
[ashok@localhost ~]$ nmcli con show
NAME                UUID                                  TYPE            DEVICE
virbr0              7ec8faaf-3b7a-4a92-9333-0a405e875b17  bridge          virbr0
Wired connection 1  7a07cec3-1711-4715-8d0f-bc543a511ecc  802-3-ethernet  --
eno16777736         d844d1c9-dac7-40dc-9cfe-ffc71461203e  802-3-ethernet  eno16777736


To list all active connections::

[ashok@localhost ~]$ nmcli con show --active
NAME         UUID                                  TYPE            DEVICE
virbr0       7ec8faaf-3b7a-4a92-9333-0a405e875b17  bridge          virbr0
eno16777736  d844d1c9-dac7-40dc-9cfe-ffc71461203e  802-3-ethernet  eno16777736
[ashok@localhost ~]$



to view the details of specific connections:
[ashok@localhost ~]$ nmcli con show eno16777736
connection.id:                          eno16777736
connection.uuid:                        d844d1c9-dac7-40dc-9cfe-ffc71461203e
connection.interface-name:              eno16777736
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.timestamp:                   1454379297
connection.read-only:                   no
connection.permissions:
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
802-3-ethernet.port:                    --
802-3-ethernet.speed:                   0
802-3-ethernet.duplex:                  --
802-3-ethernet.auto-negotiate:          yes
802-3-ethernet.mac-address:             --
802-3-ethernet.cloned-mac-address:      --
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu:                     auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype:            --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan:             1 (default)
802-3-ethernet.wake-on-lan-password:    --
ipv4.method:                            auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.gateway:                           --
ipv4.routes:
ipv4.route-metric:                      -1
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv6.method:                            auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.gateway:                           --
ipv6.routes:
ipv6.route-metric:                      -1
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
GENERAL.NAME:                           eno16777736
GENERAL.UUID:                           d844d1c9-dac7-40dc-9cfe-ffc71461203e
GENERAL.DEVICES:                        eno16777736
GENERAL.STATE:                          activated
GENERAL.DEFAULT:                        yes
GENERAL.DEFAULT6:                       no
GENERAL.VPN:                            no
GENERAL.ZONE:                           --
GENERAL.DBUS-PATH:                      /org/freedesktop/NetworkManager/ActiveConnection/0
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/Settings/0
GENERAL.SPEC-OBJECT:                    /
GENERAL.MASTER-PATH:                    --
IP4.ADDRESS[1]:                         192.168.1.101/24
IP4.GATEWAY:                            192.168.1.1
IP4.DNS[1]:                             208.59.247.45
IP4.DNS[2]:                             208.59.247.46
IP4.DNS[3]:                             192.168.1.1
IP4.DOMAIN[1]:                          cable.rcn.com
DHCP4.OPTION[1]:                        requested_domain_search = 1
DHCP4.OPTION[2]:                        requested_nis_domain = 1
DHCP4.OPTION[3]:                        requested_time_offset = 1
DHCP4.OPTION[4]:                        requested_broadcast_address = 1
DHCP4.OPTION[5]:                        requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[6]:                        requested_classless_static_routes = 1
DHCP4.OPTION[7]:                        requested_domain_name = 1
DHCP4.OPTION[8]:                        expiry = 1454463610
DHCP4.OPTION[9]:                        domain_name = cable.rcn.com
DHCP4.OPTION[10]:                       next_server = 0.0.0.0
DHCP4.OPTION[11]:                       broadcast_address = 192.168.1.255
DHCP4.OPTION[12]:                       dhcp_message_type = 5
DHCP4.OPTION[13]:                       requested_subnet_mask = 1
DHCP4.OPTION[14]:                       dhcp_lease_time = 86400
DHCP4.OPTION[15]:                       routers = 192.168.1.1
DHCP4.OPTION[16]:                       ip_address = 192.168.1.101
DHCP4.OPTION[17]:                       requested_static_routes = 1
DHCP4.OPTION[18]:                       requested_interface_mtu = 1

 TO view the status of device and its details:
[ashok@localhost ~]$ nmcli dev status
DEVICE       TYPE      STATE         CONNECTION
virbr0       bridge    connected     virbr0
eno16777736  ethernet  connected     eno16777736
virbr0-nic   ethernet  disconnected  --
lo           loopback  unmanaged     --

COnfiguring host name and name resolution ::

[root@localhost ~]# hostname
localhost.localdomain


[root@localhost ~]# hostnamectl set-hostname ashok.expanor.com
[root@localhost ~]# hostname

To check the status
[root@localhost ~]# hostnamectl status
   Static hostname: ashok.expanor.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 544bc3a26e5840ce9f5be98967078dd4
           Boot ID: 817341ebd2e647b48d6e10eed6183368
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64


[root@localhost ~]# cat /etc/hostname
ashok.expanor.com

 The host HOSTNAME used to test DNS server connectivity..

root@localhost ~]# host ashok.expanor.com
ashok.expanor.com has2.168.11.4i3 address 66.96.147.120
ashok.expanor.com mail is handled by 30 mx.expanor.com.


getent hosts hostname command is used to test host name resolution with the /etc/hosts..

root@localhost ~]# getent hosts ashok.expanor.com
66.96.147.120   ashok.expanor.com




practice exercises::
IPADRR=10.0.2.1 /etc/sysconfig/network-scripts/ifcfg-lab1
[root@ashok1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-lab1
[root@ashok1 ~]# echo "PREFIX=24 /etc/sysconfig/network-scripts/ifcfg-lab1
> ^C
[root@ashok1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-lab1
[root@ashok1 ~]# echo "IPADDR=10.0.2.1" >> /etc/sysconfig/network-scripts/ifcfg-lab1
[root@ashok1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-lab1
[root@ashok1 ~]# echo "10.0.2.1 private " >> /etc/hosts
[root@ashok1 ~]# vi  /etc/hosts
[root@ashok1 ~]# hostname

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