25 Kasım 2019 Pazartesi

samba icin script ile kullanıcı oluşturulması

Aşağıdaki script sistemde docs grubunu oluşturarak, iki dane  kullanıcıyı docs grubuna ekleyerek, sambada kullanıcı açarak, parolasını ayarlar.

#########################################
#!/bin/sh
set -x
groupadd -g 10101  docs
useradd    -g 10101 -u 10101 docsadmin1 docsadmin2


passwd="sambadaminpass"

for user in docsadmin1 docsadmin2
do
echo -ne "${passwd}\n${passwd}\n"|smbpasswd -a -s ${user}
done


#########################################

linux sistemlerde samba ile mount edilmiş bir bölümü birden fazla kullanıcı kullanacaksa, smb sisteme bağlanırken, multiuser,sec=ntlmssp paremetreleri ile bağlamak gerekiyor.
fstaba örnek;
//samba.sunucu.local/share /mnt/share cifs credentials=/etc/samba/credentials-share.txt,multiuser,sec=ntlmssp 0 0

bu şekilde sisteme bağlanmış bölüme kullanıcılar erişeceği zaman, öncelikle kendilerini cifs alanında yetkilendirmesi gerekiyor;

$ cifscreds add samba.sunucu.local

samba.sunucu.local bizim samba sunucumuz oluyor.

24 Kasım 2019 Pazar

gfs2 de bir dosya sisteminin boyutunu artırmak veya gfs dosya sistemi oluşturmak

gfs2 de mevcut dosya sisteminin boyutunun artırmak için, volume group içinde yeterli alan varsa, lv artırarak, gfs2 genişletebiliriz.


Yeni bir dosya sistemi oluşturmakta, mevcut bir dosyas sistemini genişletmek kadar kolay.
Önemli olan volume grupda boş alan olması veya yeni bir volume grup oluşturulması.



Yeni dosya sistemi oluştururken dikkat etmemiz gereken en önemli nokta, jurnal sayısını.
Kaç tane node mevcut dosya sistemini kullanacaksa jurnal size o  değere eş olmalı. 2 node varsa, jurnal sayısı 2 oluyor.

 mkfs.gfs2 -t rhelclstr:cache -j2 -J64 /dev/shared_cache/mail                                       
/dev/shared_cache/mail is a symbolic link to /dev/dm-7                                                               
This will destroy any data on /dev/dm-7
Are you sure you want to proceed? [y/n] y
Discarding device contents (may take a while on large devices): Done
Adding journals: Done
Building resource groups: Done
Creating quota file: Done
Writing superblock and syncing: Done
Device:                    /dev/shared_cache/mail
Block size:                4096
Device size:               0.29 GB (76800 blocks)
Filesystem size:           0.29 GB (76796 blocks)
Journals:                  2
Journal size:              64MB
Resource groups:           3
Locking protocol:          "lock_dlm"
Lock table:                "rhelclstr:cache"
UUID:                      0374ee2c-873a-4d5f-9c36-5ee0715e51e3





gfs2 de bir dosya sisteminin boyutunu artırmak veya gfs dosya sistemi oluşturmak

gfs2 de mevcut dosya sisteminin boyutunun artırmak için, volume group içinde yeterli alan varsa, lv artırarak, gfs2 genişletebiliriz.


Yeni bir dosya sistemi oluşturmakta, mevcut bir dosyas sistemini genişletmek kadar kolay.
Önemli olan volume grupda boş alan olması veya yeni bir volume grup oluşturulması.



Yeni dosya sistemi oluştururken dikkat etmemiz gereken en önemli nokta, jurnal sayısını.
Kaç tane node mevcut dosya sistemini kullanacaksa jurnal size o  değere eş olmalı. 2 node varsa, jurnal sayısı 2 oluyor.

 mkfs.gfs2 -t rhelclstr:cache -j2 -J64 /dev/shared_cache/mail                                       
/dev/shared_cache/mail is a symbolic link to /dev/dm-7                                                               
This will destroy any data on /dev/dm-7
Are you sure you want to proceed? [y/n] y
Discarding device contents (may take a while on large devices): Done
Adding journals: Done
Building resource groups: Done
Creating quota file: Done
Writing superblock and syncing: Done
Device:                    /dev/shared_cache/mail
Block size:                4096
Device size:               0.29 GB (76800 blocks)
Filesystem size:           0.29 GB (76796 blocks)
Journals:                  2
Journal size:              64MB
Resource groups:           3
Locking protocol:          "lock_dlm"
Lock table:                "rhelclstr:cache"
UUID:                      0374ee2c-873a-4d5f-9c36-5ee0715e51e3





29 Eylül 2019 Pazar

squid kurulumdan ipc hatası

Squid kurulurken aşağıdaki gibi bir hata mesajı alıyorsanız;

grep squid-cf__metadata.sh /var/log/messages
Sep 29 08:05:33 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:15:37 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:16:07 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:17:26 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:18:55 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:21:18 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:33:48 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:33:51 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
Sep 29 08:37:21 rhel7-satellite squid: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (13) Permission denied
[root@rhel7-satellite ~]#



fstab aşağıdaki satırı ekleyip,

shm /dev/shm tmpfs nodev,nosuid,noexec 0 0

mount -a
demeniz sorunu çözebilir.

31 Temmuz 2019 Çarşamba

selinux aksaklık nedeninin incelenmesi

selinux kullanmaya başladığımızda, audit ile ilgili sorun yaşamaya başladıysak ilk yapmamız gereken nedeni sorunun nedenini sisteme sormak olur.

Öncelikle için policy paketleri ile ilgili policycoreutils-python-2.5-29.el7_6.1.x86_64 paket yüklenmiş olmalı.

[root@rhel7lab01 ~]#
[root@rhel7lab01 ~]# yum info policycoreutils-python-2.5-29.el7_6.1.x86_64
Loaded plugins: langpacks, priorities, product-id, ps, remove-with-leaves, search-disabled-repos, show-leaves, subscription-manager, upgrade-helper
Installed Packages
Name        : policycoreutils-python
Arch        : x86_64
Version     : 2.5
Release     : 29.el7_6.1
Size        : 1.2 M
Repo        : installed
From repo   : rhel-7-server-rpms
Summary     : SELinux policy core python utilities
URL         : http://www.selinuxproject.org
License     : GPLv2
Description : The policycoreutils-python package contains the management tools use to manage
            : an SELinux environment.

[root@rhel7lab01 ~]#

Paket yüklüyse, öncelikle izin verilmeyen işlemleri listeleri, hangisi bizim aksaklığımızla alakalı ise audit bilgisini alarak izin verebiliriz

 grep  denied /var/log/audit/audit.log

[root@rhel7lab01 ~]# grep 1564549471.069:2262  /var/log/audit/audit.log |audit2why
type=AVC msg=audit(1564549471.069:2262): avc:  denied  { read } for  pid=15715 comm="nginx" name="/" dev="dm-2" ino=64 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=dir permissive=0

        Was caused by:
                Missing type enforcement (TE) allow rule.

                You can use audit2allow to generate a loadable module to allow this access.

type=AVC msg=audit(1564549408.164:2259): avc:  denied  { read } for  pid=15703 comm="nginx" name="/" dev="dm-2" ino=64 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=dir permissive=0                                                           

        Was caused by:
                Missing type enforcement (TE) allow rule.

                You can use audit2allow to generate a loadable module to allow this access.

type=AVC msg=audit(1564549419.241:2260): avc:  denied  { read } for  pid=15703 comm="nginx" name="rhel7" dev="dm-2" ino=67159104 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:unlabeled_t:s0 tclass=dir permissive=0                                             

        Was caused by:
                Missing type enforcement (TE) allow rule.

                You can use audit2allow to generate a loadable module to allow this access.

incelediğimiş işlem güvenebileceğimiz bir işlemse buna izin aşağıdaki gibi izin verebiliriz.


[root@rhel7lab01 ~]# grep nginx   /var/log/audit/audit.log |audit2allow   > nginx.te
[root@rhel7lab01 ~]# cat nginx.te 


#============= httpd_t ==============

#!!!! WARNING: 'unlabeled_t' is a base type.
allow httpd_t unlabeled_t:dir read;
[root@rhel7lab01 ~]# 

[root@rhel7lab01 ~]# grep nginx   /var/log/audit/audit.log |audit2allow  -M nginx 
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i nginx.pp

[root@rhel7lab01 ~]# semodule -i nginx.pp
[root@rhel7lab01 ~]# 

selinux kullanıyorsak, sistemimizde yüklü olması faydalı olacak paketlerden bir taneside setools-console paketi. Bu paket yüklü değilse;
yum install setools-console
yükleyebiliriz. Bu kapetle gelen araçlardan bir taneside seinfo.
seinfo ile tüm selinux ile ilgili tip/etiketleri görebiliriz.
Bu komutu direk kullanacak olursak çok fazla bilgi ekrana yazılır.
# seinfo -t |wc -l
4448
 Bundan dolayı http ile ilgili olanları görmek istiyorsak;
seinfo -t |grep http


Sistemimizdeki varsayılan selinux etikelerini görmek için semanage aracından faydalanabiliriz.

[root@server1 ~]# semanage fcontext -l

Şayet web dizinimizi standart bir dizinden farklı bir yere ayarladığımızda ayarladığımız dizinin web sunucusu tarafından okunmasına izin verilmesi için semanage ile izin vermemiz gerekiyor.

örneğin web  kök dizinimizi /var/www/html den /web dizinine çevirecek olursak,
web servisininin bu dizini okuyabilmesi için aşağıdaki gibi /web dizinini etiketleriz.

semanage fcontext  -a -t httpd_sys_content_t '/web(/.*)?'

daha detaylı işlemler yapmak istiyorsak aşağıdakileri inceleyebiliriz.
# seinfo -t |grep httpd_sys
   httpd_sys_content_t
   httpd_sys_htaccess_t
   httpd_sys_ra_content_t
   httpd_sys_rw_content_t
   httpd_sys_script_t
   httpd_sys_script_exec_t

ilave olarak kullanıcılar kendi homedizinlerinde web yayını yapacaklarsa;
httpd_enable_homedirs  özelliğini on yapmamız gerekiyor. Varsayılan olarak off dur ve selinux aktif olan sistemde normal kullancıları home dizinlerinde web yayını yapamazlar.

httpd_enable_homedirs --> off
setsebool -P httpd_enable_homedirs  on








21 Temmuz 2019 Pazar

kendi ssl sertifikamızı oluşturmak

Aşağıdaki script ile kolay bir şekilde oluşturabiliriz.


remzi@han:/tmp/sslcert$ cat ~/bin/create-self-cert.sh
#!/bin/bash
set +x
if [ $# -eq  "1" ]
then
certname=$1
else
certname=`hostname -f`
fi
# openssl genrsa -des3 -out $certname.key  2048
openssl genrsa -out $certname.key  2048
openssl req    -new  -key $certname.key -out $certname.csr
openssl x509   -req  -days 3650 -in $certname.csr -signkey $certname.key -out $certname.cert



Kullanımı:

remzi@han:/tmp/sslcert$ ./create-self-cert.sh localhost


30 Haziran 2019 Pazar

cd/dvd kalıbı oluşturmada kullandığım script

# cat   createiso.sh
#!/bin/bash
export name=$1
genisoimage -U -r -v -T  -allow-limited-size -input-charset iso8859-9 --joliet -joliet-long -V $name -volset $name  -o $name.iso  $name/




Ne işe yarar; sar -n DEV

sar -n DEV|awk 'BEGIN{mak=0} !/txpck|x86|CPU|^[ \t]*$/{if (mak