Skip to content

Instantly share code, notes, and snippets.

View aamsur-mkt's full-sized avatar

Aam S aamsur-mkt

View GitHub Profile
@aamsur-mkt
aamsur-mkt / check-ssl.sh
Created October 7, 2019 10:44
Check ssl certs is ok
openssl s_client -showcerts -connect mail.nixcraft.net:443
@aamsur-mkt
aamsur-mkt / create-user.psql
Last active October 8, 2020 06:41
Create user psql
$ sudo -u postgres psql
postgres=# create user myuser with encrypted password 'myfuser';
postgres=# grant all privileges on database yourfdatabasename to myfuser;
postgres=# GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO myfuser;
postgres=# alter default privileges in schema public
grant SELECT, INSERT, UPDATE, DELETE on tables to liman;
@aamsur-mkt
aamsur-mkt / mysqlbackups3.sh
Created October 18, 2019 15:21
Auto backup mysql to s3
# install s3cmd
# config s3cmd first with s3cmd --configure
# run mkdir /backup/mysql_dump/logs -p
#!/bin/bash
#I use this to create a little bash script that will backup the database at regular intervals, and I’ll even chuck in deleting backups older than 15 days and move the dump_file in S3_bucket.
#create a few variables to contain the Database_credentials.
# Database credentials
USER="root"
PASSWORD="root"
@aamsur-mkt
aamsur-mkt / postgrebackups3.sh
Created October 18, 2019 15:22
Auto backup postgres to s3
# install s3cmd
# config s3cmd first with s3cmd --configure
# run mkdir /backup/postgres_dump/logs -p
#!/bin/bash
#I use this to create a little bash script that will backup the database at regular intervals, and I’ll even chuck in deleting backups older than 15 days and move the dump_file in S3_bucket.
#create a few variables to contain the Database_credentials.
# Database credentials
DB_NAME="mypostgresdbname"
@aamsur-mkt
aamsur-mkt / grant-user.psql
Created October 21, 2019 08:38
re Grant Permission Previliges Postgre User
\connect your_database;
REVOKE ALL ON DATABASE your_database FROM yourf_name;
GRANT CONNECT ON DATABASE your_database TO yourf_name;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO yourf_name;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO yourf_name;
@aamsur-mkt
aamsur-mkt / create-user-readonly.psql
Last active November 13, 2019 04:11
Create user read only postgresql
# 1. To create a new user in PostgreSQL:
CREATE USER username WITH ENCRYPTED PASSWORD 'your_password';
#2. GRANT the CONNECT access:
GRANT CONNECT ON DATABASE database_name TO username;
#3. Then GRANT USAGE on schema:
GRANT USAGE ON SCHEMA schema_name TO username;
#4. GRANT SELECT
@aamsur-mkt
aamsur-mkt / netstat-nlpt.sh
Created November 6, 2019 07:34
Show Listening Port Ubuntu
#netstat -nlpt
=====================
example output
=====================
@aamsur-mkt
aamsur-mkt / netstat-ntu.sh
Last active November 15, 2019 03:58
Show list out connection ubuntu
#netstat -nputw
=====================
example output
=====================
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
@aamsur-mkt
aamsur-mkt / show-ip-ddos-attackers.sh
Last active April 13, 2020 06:22
Show incoming ddos attackers IP and Its connection
#netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r
=============================
example output
=============================
@aamsur-mkt
aamsur-mkt / limt_req_zone_whitelist
Last active November 1, 2023 12:23 — forked from skaag/limt_req_zone_whitelist
A way to whitelist certain IP ranges from limit_req_zone in nginx
geo $whitelist_ip {
default 1;
# Your office ip
127.0.0.1/32 0;
}
map $whitelist_ip $default_limit {
1 $binary_remote_addr;
0 "";