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)