vsftpd and pam

We will be using PAM to deny access to the VSFTPD service to certain users.
  1. Install the VSFTPD FTP server.
yum install vsftpd
  1. Start the service and verify it is running.
systemctl start vsftpdsystemctl status vsftpd
[OUTPUT]
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-02-24 13:39:42 CST; 5min ago
  Process: 17739 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 17741 (vsftpd)
   Memory: 592.0K
   CGroup: /system.slice/vsftpd.service
           └─17741 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
  1. Install the FTP client utility.
yum install ftp
  1. Using the client, verify that the user account can log in to the server.
ftp localhost
[output]
Connected to localhost (127.0.0.1).
220 (vsFTPd 3.0.2)
Name (localhost:root):
  1. Display the contents of the PAM VSFTP module, note the file referred to for denying user access.
cat /etc/pam.d/vsftpd
[output]
#%PAM-1.0
session    optional     pam_keyinit.so    force revoke
auth       required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required pam_shells.so
auth       include password-auth
account    include password-auth
session    required     pam_loginuid.so
session    include password-auth
  1. Add the user account to the appropriate file noted from Step 5.
vim /etc/vsftpd/ftpusers
[contents with our setting on last line]
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
user
  1. Verify the user account is no longer permitted to log in.
ftp localhost
[output]
Connected to localhost (127.0.0.1).
220 (vsFTPd 3.0.2)
Name (localhost:root): user
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> quit
221 Goodbye.

parted extend the expanded disk

root@server:# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free                                                  
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
    25.8GB  25.8GB 3584B   Free Space
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
    1100GB  2199GB 1100GB  Free Space

(parted) mkpart
Partition name?  []? <you can leave it blank>                                           
File system type?  [ext2]? zfs                                       
Start? 1100GiB                                                       
End? 100%                                                            
(parted) print                                                       
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
6   1181GB  2199GB 1018GB  zfs # this is the new one created

(parted) quit
Information: You may need to update /etc/fstab.


UEFI/GPT examples

In every instance, a special bootable EFI System Partition is required.
If creating a new EFI System Partition, use the following commands (the recommended size is 512MiB):
(parted) mkpart ESP fat32 1MiB 513MiB
(parted) set 1 boot on
The remaining partition scheme is entirely up to you. For one other partition using 100% of remaining space:
(parted) mkpart primary ext4 513MiB 100%
For separate / (20GiB) and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary ext4 20.5GiB 100%
And for separate / (20GiB), swap (4GiB), and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary linux-swap 20.5GiB 24.5GiB
(parted) mkpart primary ext4 24.5GiB 100%

Case vmware expanded

There's a difference between rescanning for new disks at the adapter level and rescanning for update size information at the disk level.
echo "- - -" > /sys/class/scsi_host/host#/scan
Sending "- - -" to /sys/class/scsi_host/host[012]/scan is telling the SCSI host adapter to look for new disks on every channel "(-)", every target "(-)", and every lun "(-)". - this is the right thing to do if you add a new disk to the system while it's powered on.
echo “1” > /sys/class/block/sdc/device/rescan
Sending a "1" to /sys/class/block/sdc/device/rescan is telling the SCSI block device to refresh it's information about where it's ending boundary is (among other things) to give the kernel information about it's updated size. - this is the right thing to do if you change the size of an existing disk while it's powered on.



Came back to using parted again today and this is how to properly create a partition using parted and getting rid of the alignment error:

Code:
root@loadtest01:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt                                                      
(parted) mkpart                                                           
Partition name?  []? primary                                        
File system type?  [ext2]? linux-swap                                    
Start? 0%                                                                 
End? 100%                                                                 
(parted) print                                                            
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start End     Size File system  Name Flags
1      1049kB 17.2GB  17.2GB     primary

(parted) align-check                                                      
alignment type(min/opt)  [optimal]/minimal? optimal                       
Partition number? 1                                                       
1 aligned

Increasing nofiles pam ulimit

cat /proc/{process_id}/limits:

$ cat /proc/1882/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max open files            4096                 4096                 files
Max locked memory         65536                65536                bytes

it looks like 4096 number is too low for elastic search , now checking if the limit is reached for this PID
 /proc/{process_id}/fd is a directory that holds a file for each open file the process has,
 ls /proc/1882/fd | wc -l


/etc/pam.d/common-session needs to have this line in it:
session required pam_limits.so

/etc/pam.d/common-session-noninteractive also needs to have this line in it:
session required pam_limits.so

How to find ulimit for www-data user ?


# su www-data --shell /bin/bash --command "ulimit -aH" 
#  ulimit -aS ->will give soft limit

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3900
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3900
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

system tuning for database servers

Virtual Memory

Dirty Ratio

Page cache on a Linux system is the area where filesystem based I/O is cached and that these settings affect how the cache is utilized by the kernel.
We can tune pdflush to determine how much RAM based cache to use for (dirty pages) data targeted to disk and how frequently to flush that cached data by writing the pages back to disk.
The “dirty_ratio” is the percentage of total system memory that can hold dirty pages. The default on most Linux hosts is between 20-30%. When you exceed the limit, the dirty pages are committed to disk, creating a small pause. To avoid this hard pause, there is a second ratio: “dirty_background_ratio” (default 10-15%), which tells the kernel to start flushing dirty pages to disk in the background without any pause.
20-30% is a good general default for “dirty_ratio,” but on large-memory database servers, this can be a lot of memory! For example, on a 128GB-memory host, this can allow up to 38.4GB of dirty pages. The background ratio won’t kick in until 12.8GB! We recommend that you lower this setting and monitor the impact to query performance and disk IO. The goal is reducing memory usage without impacting query performance negatively. Reducing caches sizes also guarantees data gets written to disk in smaller batches more frequently, which increases disk throughput (rather than huge bulk writes less often).
A recommended setting for dirty ratios on large-memory (64GB+ perhaps) database servers is: “vm.dirty_ratio = 15″ and “vm.dirty_background_ratio = 5″, or possibly less. (Red Hat recommends lower ratios of 10 and 3 for high-performance/large-memory servers.)
You can set this by adding the following lines to “/etc/sysctl.conf
vm.dirty_ratio=15
vm.dirty_background_ratio=5



zpool convert /dev/sdx to /dev/disk/by-id

zpool export my_pool 
zpool import -d /dev/disk/by-id/     my_pool 

Example of creating pool using by-path 

zfs create tank raidz1 pci-0000:03:00.0-scsi-0:0:21:0 pci-0000:03:00.0-scsi-0:0:19:0 pci-0000:02:00.0-scsi-0:0:9:0 pci-0000:02:00.0-scsi-0:0:11:0 pci-0000:03:00.0-scsi-0:0:22:0 pci-0000:03:00.0-scsi-0:0:18:0

ls -l /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root  9 Mar 23 14:01 pci-0000:00:07.1-ata-2 -> ../../sr0
lrwxrwxrwx 1 root root  9 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part9 -> ../../sda9

Drawbacks of /dev/sdx way:The names are not persistent and will change depending on what order they disks are detected in. Adding or removing hardware for your system can easily cause the names to change. You would then need to remove the zpool.cache file and re-import the pool using the new names.

https://ubuntuforums.org/archive/index.php/t-2087726.html
https://wiki.archlinux.org/index.php/Persistent_block_device_naming#by-id_and_by-path
https://unix.stackexchange.com/questions/86764/understanding-dev-disk-by-folders

redhat test

1) command shows you critical packages that are ready to be installed?
Correct

Correct answer

yum updateinfo list --sec-severity=Critical

2) following is the common vulnerability and exposures website?
Correct

Correct answer

http://cve.mitre.org

3) command installs the yum security plugin?
Correct

Correct answer

yum install yum-plugin-security

4) command shows you critical packages that are ready to be installed?
Correct

Correct answer

yum updateinfo list --sec-severity=Critical

Explanation

The command to use for getting critical updates is the following: yum updateinfo list --sec-severity=Critical


s3-parallel-put for faster uploads

/var/www# /usr/local/bin/s3-parallel-put --bucket=mediatest.visualsociety.com --host=s3.amazonaws.com --processes=10 --put=stupid --secure --content-type=guess --log-filename=/var/log/s3upload.log  .

Tested for 600GB of data
start time: 9:00AM March14
End time:-xx
11 GB uploaded in 10 minutes so far...
digital ocean droplet (2vcpu,2GB memory) NYC region to aws-s3

github: s3-parallel-put

devstack and packstack

yum -y update
#to install packstack
yum install centos-release-qemu-ev
yum remove mariadb-libs
visudo
enable wheel by uncommenting

#disable selinux
vim /etc/selinux/config
selinux=disabled

#disable Networkmanager and firewalld
systemctl disable NetworkManager firewalld

yum search openstack  #look for latest at bottom here its ocata
yum install -y install centos-release-openstack-ocata
yum install -y openstack-packstack
packstack --gen-answer-file=/home/user1/answers.txt
edit the answers.txt
change password=config_default_password=openstack
config_magnum_install=y #for container orchestration
config_keystone_admin_pw=xxxxxx
config_keystone_demo_pw=xxxx
save file
#start packstack installation
packstack --answwer-file=/home/user1/answers.txt


# Devstack on ubuntu
adduser stack
add it to sudo user without password
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
su stack
apt-get install git
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
vim local.conf
[[local|localrc]]
ADMMIN_PASSWORD=openstack
DATABASE_PASSWORD=openstack
RABBIT_PASSWORD=openstack
SERVICE_PASSWORD=openstack

tcpdump


# Type Qualifier

host, net, port, portrange

tcpdump -v net 12.12.12.0 mask 255.255.255.0 
tcpdump -v net 12.12.12.0/24  or tcpdump -v net 11.11.11   #capture from /24 network
tcpdump -v host 33.33.33.33

tcpdump -v port 80  - capture all traffic to-or-from port 80
tcpdump -v portrange 21-80


# Directional Qualifier
src, dst, src or dst, src and dst

tcpdump -v  src 1.1.1.1 . (show pkt COMING from 1.1.1.1 only)
tcpdump -v dst 1.1.1.1 (show pkt Going to 1.1.1.1)

#Protocol Qualifier(ip,ip6,tcp,udp,icmp,ether)
eg. arp - IP to MAC resolution

tcpdump -v arp  -  show arp
tcpdump -nv ether broadcast  - shows ethernet broadcast traffic(ipp, arp traffic)
/etc/services --ipp is used to convert port number to names

tcpdump -nnv udp
tcpdump -nnv icmp

tcpdump src host 192.168.75.1 and dst port 22   - reveals TCP:22 or UDP 22 sourced/Coming from  192.168.75.1

tcpdump dst host 1.1.2.2 and dst port 22
tcpdump -c 1      # count capture 1 packet and exit
tcpdump -n -r filename.dump not port 5901 . ##exclude packet to/from 5901 tcp/udp port


iostat -xnz 1