Cheatsheet

  1. 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;
    
Bash
1
netstat -plntu | grep -i "listen"
  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>
    
  2. Mailgun Setup

    Bash
    1
    2
    apt-get update 
    apt-get install postfix libsasl2-modules
    
  3. 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
    
  4. 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"
    

  5. Hibernate Mac

  6. Find blogger feed url - add this to end

    HTML
    1
    /feeds/posts/default?alt=rss
    

  7. Download all files in directory

    Bash
    1
    wget - r - np -nH cut-dirs -R index.html http://hostname/aaa/bbb/ccc/ddd
    

  8. Generate dhparam

Bash
1
openssl dhparam -dsaparam -out /etc/ssl/private/dhparam.pem 4096
  1. Check system logs for a service

    Bash
    1
    journalctl -u <service.name> -f
    
  2. 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

  3. Setup rTorrent with ruTorrent

  4. Jekyll

    • Run on custom host
    Bash
    1
    bundle exec jekyll serve -H 10.8.0.1
    
  5. Nmap

    • Scan for open ports
    Bash
    1
    nmap -sS -sU -PN -p 1-65535 thedoc.eu.org
    
  6. Open port on SSH

    Bash
    1
    ssh -L <localPort>:127.0.0.1:<remotePort> sshConfig
    
  7. 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>
    
  8. To add users to a group

    Bash
    1
    2
    sudo usermod -aG <grp_toadd> user
    sudo chmod g+rw <folder>
    
  9. Forward SSH port to localhost

    Bash
    1
    ssh -L <localPort>:localhost:<remotePort> <server_config>
    
  10. Change text in any file using bash/sed

    Bash
    1
    sed -i 's/original/new/g' file.txt
    
  11. Repeat a command in bash every n seconds

    Bash
    1
    while :; do clear; <command> ; sleep < n seconds >; done
    
  12. 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
    
  13. 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