Cheatsheet
-
Add new user and database to Mysql
SQL 1 2 3 4
Create database ‘<database>’; CREATE USER '<user>'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON <database>.* TO <user>@‘localhost'; FLUSH PRIVILEGES;
-
Enable logging without restarting
Bash 1 2
SET GLOBAL general_log = 'ON'; SET GLOBAL slow_query_log = 'ON';
-
Disable runtime logging
Bash 1 2
SET GLOBAL general_log = 'OFF'; SET GLOBAL slow_query_log = 'OFF';
-
https://www.pontikis.net/blog/how-and-when-to-enable-mysql-logs
-
List listening ports
Bash | |
---|---|
1 |
|
-
Docker
- Update after files change
Bash 1
docker-compose up -d --build
- Logs
Bash 1
docker-compose logs -f -t
- Destroy all docker images
Bash 1 2 3 4
docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) docker rmi $(docker images -q) docker exec <name> <command>
-
Mailgun Setup
Bash 1 2
apt-get update apt-get install postfix libsasl2-modules
-
Add to /etc/postfix/main.cf
bash smtp_sasl_auth_enable = yes relayhost = smtp.mailgun.org smtp_sasl_security_options = noanonymous smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
Bash 1 2 3 4 5 6 7
echo 'smtp.mailgun.org <mail>:<password>' > /etc/postfix/sasl_passwd chmod 600 /etc/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd service postfix restart sudo apt-get install -y mailutils echo "Mail test" | mail -s "Subject" root echo "This is testing SMTP Relay." | mail -s "Postfix Mailgun" $MAIL
-
Send mail on every sudo command
Bash 1 2 3 4 5
visudo -f /etc/sudoers.d/my_sudoers Defaults mail_always Defaults mailerpath=/usr/sbin/sendmail Defaults mailto="root" Defaults mailerflags="-t"
-
Find blogger feed url - add this to end
HTML 1
/feeds/posts/default?alt=rss
-
Download all files in directory
Bash 1
wget - r - np -nH cut-dirs -R index.html http://hostname/aaa/bbb/ccc/ddd
-
Generate dhparam
Bash | |
---|---|
1 |
|
-
Check system logs for a service
Bash 1
journalctl -u <service.name> -f
-
Remove commited directories from git remote branch
bash git rm -r --cached some-directory git commit -m 'Remove the now ignored directory "some-directory"' git push origin master
-
Setup rTorrent with ruTorrent
-
Jekyll
- Run on custom host
Bash 1
bundle exec jekyll serve -H 10.8.0.1
-
Nmap
- Scan for open ports
Bash 1
nmap -sS -sU -PN -p 1-65535 thedoc.eu.org
-
Open port on SSH
Bash 1
ssh -L <localPort>:127.0.0.1:<remotePort> sshConfig
-
UFW
- Allow from specific subnet
Bash 1
sudo ufw allow from <subnet/24> to any port <port-no>
- Delete rule
Bash 1
sudo ufw delete allow <port>
-
To add users to a group
Bash 1 2
sudo usermod -aG <grp_toadd> user sudo chmod g+rw <folder>
-
Forward SSH port to localhost
Bash 1
ssh -L <localPort>:localhost:<remotePort> <server_config>
-
Change text in any file using bash/sed
Bash 1
sed -i 's/original/new/g' file.txt
-
Repeat a command in bash every n seconds
Bash 1
while :; do clear; <command> ; sleep < n seconds >; done
-
Adb commands to control package manager
Bash 1 2 3 4
pm list packages pm path package.name adb install -r package.apk pm disable --user 10 package.name
-
Android Studio : Solve support library issue
- Execute in Terminal
./gradlew -q dependencies app:dependencies
- Then search for conflicting dependencies version
- add the latest version for conflicting dependencies explicitly in build.gradle
- Execute in Terminal