Showing posts with label Server. Show all posts
Showing posts with label Server. Show all posts

Tuesday, 6 September 2016

About limits.conf

You probably know about ‘nproc’ limits in Linux which are set in /etc/limits.conf
Nproc is defined at OS level to limit the number of processes per user.
Example :
user soft nproc 8192
user hard nproc 8192

Issue
Normal user is unable to login on the system with an error "fork: Resource temporarily unavailable" 
 
# su – <user> 
-bash: fork: retry: Resource temporarily unavailable 
-bash: fork: retry: Resource temporarily unavailable 
-bash: fork: retry: Resource temporarily unavailable 
-bash: fork: retry: Resource temporarily unavailable 
-bash: fork: Resource temporarily unavailable

Resolution
Increase the value of "nproc" parameter for user or all user's in /etc/security/limits.conf
 
#ps h -Led -o user | sort | uniq -c | sort -n
      1 nrpe
      1 ntp
      1 rpc
      1 rpcuser
      2 dbus
      2 postfix
      3 haldaemon
    401 wildfly
    440 root
    934 user






Set it high but monitor it when the number of processes reaches maximum of limit.
 

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


#vim /etc/security/limits.conf 
user           soft    nproc           8192
user           hard    nproc           8192
user           soft    nofile          8192
user           hard    nofile          8192





These limits will be applied after reboot.
If you want to apply changes without reboot, modify /etc/pam.d/config-util by adding this line at the end of file: 

session required pam_limits.so

Tuesday, 10 May 2016

Openssl PATCH version 1.0.1t


















Monday, 4 April 2016

Streaming Replication PostgreSQL 9.x

Setup ssh for user postgres :
[on both server]
- change password postgres :
#sudo passwd postgres
[enter password]

#su - postgres
#ssh-keygen
#ssh-copy-id -i ~/.ssh/id_rsa.pub postgres@slave_IP_address

 
PostgreSQL Configuration

On Master :
[create user for replicator]
CREATE ROLE replicator WITH REPLICATION PASSWORD 'password' LOGIN;

[add to pg_hba.conf to allow slave connect to master]
pg_hba.conf
host   replication   replicator   IP_address_of_slave/32   md5
[Some configuration for replication on master]
Edit postgresql.conf

listen_address = '*'
wal_level = hot_standby
max_wal_senders = 5
wal_keep_segments = 32
checkpoint_segments = 8
archive_mode    = on
archive_command = 'rsync -a %p postgres@IP_address_of_slave:/var/lib/pgsql/9.x/archive/%f'


On Slave :
Using basebackup

pg_basebackup -h IP_address_of_master -D /var/lib/pgsql/9.x/data -P -U replicator --xlog-method=stream
Using rsync

run query
SELECT pg_start_backup('label');
rsync -argv

SELECT pg_stop_backup();
postgresql.conf
hot_standby = on


[Disable archive mode]
#archive_mode    = on
#archive_command = 'rsync -a %p postgres@IP_address_of_slave:/var/lib/pgsql/9.x/archive/%f'


Add file recoveri.conf [at /var/lib/pgsql/9.x/data/]

Config for recovery.conf
primary_conninfo = 'host=IP_address_of_master port=5432 user=replicator password=password'
trigger_file = '/var/lib/pgsql/9.4/data/failover'
standby_mode = 'on'
restore_command = 'cp -f /var/lib/pgsql/9.x/archive/%f %p </dev/null'
archive_cleanup_command = '/usr/pgsql-9.x/bin/pg_archivecleanup -d /var/lib/pgsql/9.x/archive %r 2>>cleanup.log'



Notes :

Monday, 18 January 2016

Strong IPTABLES Configuration [CentOS]

A persistent IPtables Firewall, for securing your server.









1. Reset all rules (F) and chains (X), necessary if have already defined iptables rules
iptables -t filter -F
iptables -t filter -X

2. Start by blocking all traffic
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP

3. Keep established connexions
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

4. Allow loopback
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT

5. HTTPS
iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT

6. To allow SSH from specific IP Address
iptables -t filter -A INPUT -p tcp -s YourIP --dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT

etc,

note : Just allow the required course.

Monday, 6 July 2015

[How To] E-Mail Alerts on a CentOS Server



Required :
- sSMTP (install using yum from epel repo)
- bash script and cron

First :
Enable epel-repo :

Centos 6.x 32 Bit :
#wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6-8.noarch.rpm

Centos 6.x 64 Bit :
#wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#rpm -ivh epel-release-6-8.noarch.rpm

and than install ssmtp
#yum -y update
#yum -y install ssmtp


Change your default Mail Transfer Agent (MTA) to ssmtp
[root@ademahmudf ~]# alternatives --config mta

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*  1           /usr/sbin/sendmail.postfix
 + 2           /usr/sbin/sendmail.ssmtp

Enter to keep the current selection[+], or type selection number: 2

Next, configure the mail server info to relay outgoing email (i use gmail for example)
#mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
#mv /etc/ssmtp/revaliases /etc/ssmtp/revaliases.bak

#nano /etc/ssmtp/ssmtp.conf
root=postmaster
mailhub=smtp.gmail.com:587
Hostname=example@gmail.com
FromLineOverride=YES
AuthUser=example@gmail.com
AuthPass=email-password
UseSTARTTLS=YES
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

#nano /etc/ssmtp/revaliases
root:example@gmail.com:smtp.gmail.com:587

Next, you can start sending email using your preferred email server using command below
echo "Testing outgoing email from Centos server" | mail -s "Testing" -r sender@gmail.com receiver@gmail.com

And here we go,
Let's create an example script for notification and run with cron

#nano disk_space_notif.sh

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $4}' | sed 's/%//g')
THRESHOLD=90

if [ "$CURRENT" -ge "$THRESHOLD" ] ; then
echo "Your partition at server $HOSTNAME is critically low. Used: $CURRENT%" | mail -s "Disk Space Alert" -r sender@gmail.com receiver@gmail.com
fi

make script executable
#chmod +x disk_space_notif.sh

add cronjob for running script
#crontab -e

*  *  *  *  * /path/to/script/disk_space_notif.sh





Monday, 15 June 2015

Upgrading FreeBSD 10.1-RELEASE To -STABLE



Procedure

Move the current source code to a backup folder to be sure to get only -STABLE code:
mv /usr/src /usr/src-RELEASE
mv /usr/ports /usr/ports-RELEASE


Check out the STABLE source code:
svn checkout https://svn0.us-west.freebsd.org/base/stable/10 /usr/src
svn checkout https://svn0.us-west.freebsd.org/ports/head /usr/ports

*if svn command not found, install svn first,
pkg install devel/subversion

Then cd in to the correct folder
cd /usr/src

Build the world:
make buildworld -j2

*The -j 2 part means that it should run 2 jobs at once.

cd /usr/src/sys/i386/config
cp GENERIC yourkernelname

Build the kernel:
make buildkernel KERNCONF=yourkernelname
make installkernel KERNCONF=yourkernelname

Now reboot in to the new kernel:
shutdown -r now

Now we're giong to install the world
make installworld
After that finished we can do another mergemaster:
mergemaster -p

Almost done, time to reboot
shutdown -r now

Remove old files and libraries:
cd /usr/src
make check-old
>>> Checking for old files
>>> Checking for old libraries
>>> Checking for old directories
To remove old files and directories run 'make delete-old'.
To remove old libraries run 'make delete-old-libs'.

make delete-old
remove /usr/share/doc/atf/AUTHORS? y
remove /usr/share/doc/atf/COPYING? y
remove /usr/share/doc/atf/NEWS? y
remove /usr/share/doc/atf/README? y
remove /usr/share/man/man1/atf-check.1.gz? y
remove /usr/share/man/man1/atf-sh.1.gz? y
remove /usr/share/man/man1/atf-test-program.1.gz? y
remove /usr/share/man/man3/atf-c-api.3.gz? y
remove /usr/share/man/man3/atf-c++-api.3.gz? y
remove /usr/share/man/man3/atf-sh-api.3.gz? y
remove /usr/share/man/man4/atf-test-case.4.gz? y
remove /usr/share/mk/atf.test.mk? y
>>> Old files removed
>>> Removing old directories
>>> Old files removed

To remove old libraries run 'make delete-old-libs'.
make delete-old-libs
>>> Removing old libraries
Please be sure no application still uses those libraries, else you
can not start such an application. Consult UPDATING for more
information regarding how to cope with the removal/revision bump
of a specific library.
>>> Old libraries removed

DONE !
Run freebsd-version to see that you are now on stable:

freebsd-version
10.0-STABLE

*Note that freebsd-update does not work with the STABLE branch. 



Sunday, 22 March 2015

Install OpenVAS 7 on Ubuntu 14.04

Disini kita akan melakukan instalasi OpenVAS pada sistem operasi Linux Ubuntu dengan menggunakan Greenbone Security Assistant sebagai web client untuk memudahkan kita dalam pengoperasian OpenVAS ini.
 

Ada beberapa source files yang kita butuhkan untuk proses instalasi OpenVAS ini, diantaranya :

1. Openvas-libraries
2. Openvas-scanner
3. Openvas-manager
4. Openvas-cli
5. Greenbone-security-assistant

Langkah I
Download source files untuk openvas.
source files tersebut bisa didownload di SINI
Lalu extract kelima file tersebut dengan cara
tar zxvf [nama file].tar.gz


Langkah II
Install required packages untuk openvas ini, 

apt-get install build-essential bison flex cmake pkg-config libglib libglib2.0-dev 
libgnutls libgnutls-dev libpcap libpcap0.8-dev libgpgme11 libgpgme11-dev doxygen 
libuuid1 uuid-dev sqlfairy xmltoman sqlite3 libxml2-dev libxslt1.1 libxslt1-dev 
xsltproc libmicrohttpd-dev

Langkah III 
Proses instalasi dan compiling komponen-komponen untuk openvas.
Agar proses instalasi berjalan dengan lancar, pertama kita akan install openvas-libraries terlebih dahulu.
 Lakukan langkah-langkah berikut :

1. Masuk ke direktori openvas-libraries dengan cara | cd [nama direktori]
2. Pada direktori tersebut buat folder dengan nama source | mkdir source
3. Masuk ke direktori source | cd source
4. Ketikan | cmake ..
5. make
6. make install  

Proses compiling and installing openvas-libraries sudah selesai, selanjutnya lakukan langkah-langkah tersebut untuk komponen-komponen yang lainnya (Openvas-scanner, Openvas-manager, Openvas-cli, Greenbone-security-assistant)
Lakukan seperti langkah-langkah diatas.

Setelah semua selesai lakukan perintah-perintah berikut :
openvas-mkcert
ldconfig
openvassd
 
Check kalau openvassd sudah berjalan dengan baik.
ps -ef | grep openvas
 
Langkah IV
Sekarang Lets sync NVT plugins and the vulnerability data.
openvas-nvt-sync
openvas-scapdata-sync
openvas-certdata-sync
 
Buat user account dan client certificate.
openvasmd --create-user=admin --role=Admin
openvas-mkcert-client -n -i

Sekarang kita start semua service-nya dengan cara
openvassd  
openvasmd 
gsad

Lalu setelah itu ketikan : 
openvasmd --rebuild --progress
openvasmd
gsad

SELESAI
Sekarang kita buka dari browser dengan cara mengetikan https://[ip-server]
Ingat menggunakan https karena greenbone-security-assistant running pada port 443.

Jika ada yang ingin ditanyakan atau tidak jelas, silahkan comment diposting ini. ^^
 

Saturday, 21 March 2015

Performing Local security check with openVAS

Kali ini saya akan membahas tentang sebuah software yang bernama openVAS.
OpenVAS sendiri adalah  merupakan software yang digunakan untuk mengetes vulnerability sebuah server / security check yang merupakan versi gratisan dari nessus.
Terlepas dari gratisan, namun software ini sangat bermanfaat sekali.

Berikut saya berikan contoh penggunaan OpenVAS. Dalam hal ini saya install OpenVAS di OS Ubuntu yang dimana akan melakukan local security check terhadap sebuah server (Ubuntu Server 12.04)
Ini adalah tampilan awal

Setelah login, akan muncul tampilan seperti diatas. Disini terlihat ada 1 hasil scanning yang sudah complete. Untuk mulai scanning kita cukup masukan alamat host yang akan kita scan di kolom start scan.

Ini adalah hasil dari scanning. Dimana terlihat dari scan resultnya ada beberapa vurnarebilty.

Dan ini adalah detail dari vurnerability yang didapat dari hasil scanning. Dimana terlihat ada 1 ancaman yang sangat berbahaya, yaitu bug pada bash yang disebut "shellshock"

Selain itu, kita juga bisa melihat detail dari setiap vulnerabilty yang ada. Disini kita ambil contoh yang shellshock, kita akan tahu jenis serangan apa yang mungkin dilakukan oleh attacker dan apa dampak yang ditimbulkan. Dan kerennya lagi kita diberi tahu cara untuk menangani bug / ancaman tersebut.


Dari hasil tersebut kita dapat mengetahui seberapa aman server tersebut dan ancaman apa saja yang mungkin terjadi pada server tersebut. Disini kita juga bisa mengetahui detail dari celah keamanan tersebut serta dapat mengetahui solusi yang bisa dilakukan untuk menanggulanginya.
Ini adalah dasar dari penggunaan software OpenVAS dan untuk lebih lanjutnya silahkan "oprek" sendiri. ^^

Install OpenVAS 7 on Ubuntu 14.04

Thursday, 15 March 2012

Install DNS Server on Debian via webmin






Hi kali ini saya mau share lagi nih, nerusin tutorial yang kemaren instalasi webmin di debian. sekarang lanjut ke instalasi bind9/DNS dengan menggunakan webmin. check it out kakaaa :)


catatan : karena kemaren nyoba langsung upload ke blog ternyata jelek, jadi sekarang lewat youtube biar agak jelas videonya. semoga bermanfaat :)

http://www.youtube.com/watch?v=gTmNBXdLn8g

Wednesday, 14 March 2012

Instalasi Webmin di Debain Server


semoga bermanfaat :)


 keterangan :
disini saya pake virtualbox buat Install linux debian nya, dan windows 7 sebagai client nya.
sebelum installasi, pastikan settingan IP di debian server dan di laptop kita udah di setting, agar debian dengan laptop kita sudah terkoneksi.
settingan di video
IP Debian server : 192.168.20.1
IP Laptop           : 192.168.20.2
kalo udah di sett, kita masuk ke direktori file instalan webmin nya. (liat video)
lalu lakukan perintah-perintah berikut :
1. ekstrak file webmin dengan cara mengetikan "dpkg -i (nama filenya) contoh : dpkg -i webmin_123_all.deb (lalu enter)
2. lakukan instalasi dengan cara mengetika "apt-get -f install". pilih "yes" lalu tunggu samapi proses selesai.
3. jika sudah selesai, masuk ke browser dari laptop kita. lalu masuk ke alamat webmin nya.
    "https://ip-debian-server:10000" karena IP debian adalah 192.168.20.1 dan port default webmin adalah 10000, maka kita masukan alamat sebagai berikut "https://192.168.20.1:10000"

binggooo kita udah berhasil melakukan instalasi webmin. gampang kan ? :)

catatan : username dan password defaultnya adalah root (user : root, pass : root)

video yang lebih bagus bisa dilihat disini : http://www.youtube.com/watch?v=_S44gVd02EY