Skip to content

Instantly share code, notes, and snippets.

View SeyedMostafaAhmadi's full-sized avatar

SeyedMostafaAhmadi

View GitHub Profile
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / restrict-sftp
Last active March 11, 2022 15:44
How to Restrict SFTP Users to Home Directories Using chroot Jail
# Create Group and User
groupadd your-groupname
adduser your-username --shell /sbin/nologin
# add your-username to your-groupname
usermod -aG your-groupname your-username
# Modify SSH Configuration File in /etc/ssh/sshd_config
Subsystem sftp internal-sftp
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / create-vm-in-kvm
Created January 18, 2022 11:25
Create vm in kvm with virt-install command
virt-install --name=test\
--ram=2048 --os-type=linux\
--cdrom=/var/lib/libvirt/images/debian-9.4.0-amd64-xfce-CD-1.iso\
--disk path=/dev/mapper/vg_kvm-db21_root\
--disk path=/dev/mapper/vg_kvm-db21_tmp\
--disk path=/dev/mapper/vg_kvm-db21_swap\
--network bridge=br0\
--vnc --noautoconsole
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / useful-commands-in-mysql
Last active December 25, 2021 05:59
Useful commands in mysql
### create user name with specific password
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
### create database
CREATE DADTABASE database-namee;
### grant all privileges to user for all databases
GRANT ALL PRIVILEGES ON * . * TO 'username'@'localhost';
### grant all privileges to user for specific database
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / set-bridge-for-tor
Created November 7, 2021 10:13
Set bridge for tor
# go to here path and add follow lines to this file /etc/tor/torrc
# previous install "obfs4proxy" package
####
UseBridges 1
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy
Sandbox 0 # don't work with ClientTransportPlugin
Bridge obfs4 51.195.117.252:666 3275695F343201E2243B0E55E6C2F6476BDC91A7 cert=KybiRTmKQZiQmLk/Iuq9BHjWgIgHsbZ0pzrZCTZDeA6N7KWInqTxZc9TPpSfs88t25+MPA iat-mode=0
Bridge obfs4 87.106.157.198:55405 3C3893086B27E879778E4A6275E5230AA49132E9 cert=uZorJsxG11sfGmt2tsJRX6jCDQF043crM0vfsY+BJUdciPsszVN1eAem2zNteZ2WVjFqLg iat-mode=0
Bridge obfs4 51.79.51.112:51804 228199E09F51A406D0A3585463A47B82A9AF11AB cert=jgFDOR4fAkVvdCLHjCYv9+WKu4oilFhSWQGSlm8nlhfQ8gYLz24p5bTsF6jYL4ZxiYMlcw iat-mode=0
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / reduce-lvm
Last active November 3, 2021 11:15
How to reduce lvm
# for reduce lv in lvm on linux
# first enter follow command
umount /dev/mapper/vg_name/lv_name
#
e2fsck -f /dev/mapper/vg_name/lv_name
#
resize2fs /dev/mapper/vg_name/lv_name [fav_space]G
#
lvreduce -L [fav_space]G /dev/mapper/vg_name/lv_name
#
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / Ckeck partition in mysql
Created October 28, 2021 06:18
Check partition in mysql
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME = 'history';
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / Header Information
Created October 20, 2021 16:52
Hide View Server Header Information
# We can stop outputting the version of nginx and os by adding below command in nginx config in /etc/ngingx/nginx.conf to a http, server, or location context.
server_tokens off;
# Or if we want to remove the Server header completely, We need to compile Nginx with the Headers More module in, as the header is hard coded in the Nginx source, and this module allows changing any http headers.
more_clear_headers Server;
# for use top module we should install "apt install nginx-extras"
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / Disable root login without password
Created October 16, 2021 11:32
Disable root login without password
SELECT host, user, password, plugin FROM mysql.user;
which should return something like this (with unix_socket enabled):
+-----------+------+--------------------------+-------------+
| host | user | password | plugin |
+-----------+------+--------------------------+-------------+
| localhost | root | <redacted_password_hash> | unix_socket |
+-----------+------+--------------------------+-------------+
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / reload udev rules without reboot
Last active November 28, 2023 06:45
How to reload udev rules without reboot?
# When i was faced with this warning in lvm when i run lvm command it works but it took
# WARNING: Device /dev/dm-20 not initialized in udev database even after waiting 10000000 microseconds.
# It look my problem is solved by reloading udev rules without reboot with this command:
udevadm control --reload-rules && udevadm trigger
@SeyedMostafaAhmadi
SeyedMostafaAhmadi / make swap partition
Last active July 11, 2021 10:47
make swap partition
swapoff -a #### Turn off the existing swap space
#### create partition with enter n character, after enter this character enter partition number and start sector and space - write changes with enter w
partprobe #### reread partition table
#### add this line `/dev/specific-device none swap sw 0 0` ### modify /etc/fstab file for mount startup
mkswap /dev/specific-partition
swapon -a #### activate created swap particion