• Things I Got Useful

  • Useful Linux Stuff

    Package files and directories

    #Compress
    tar -zcvf [result-filename.tar.gz] [path-of-dir]
    
    The -zcvf instruction stand for:
        -z: Compress the desired file/directory using gzip
        -c: Stand for create file (output tar.gz file)
        -v: To display the progress while creating the file
        -f: path of the desire file/directory to compress
    
    #Uncompress
    tar -xvzf [your-tar-file.tar.gz]  
    

    System Control

    Restart apache
    sudo systemctl restart httpd.service
    sudo systemctl start   httpd.service
    sudo systemctl stop    httpd.service
    
    restart SSH
    service sshd restart

    Delete Directory Recursively

    rm -r mydir
    Delete directory recursively with content

    Firewall Control

    #find out if an IP is blocked
    csf -g 195.68.95.198

    #remove the block
    csf -dr 195.68.95.198

    #restart the firewall
    csf -r

    SSH Setup & Permission

    #enable site for SSH private key login
    1. run ssh-keygen (use defaults)
    2. add key to .ssh/authorized_keys
    3. ensure correct permissions

    #Permissions
    chmod 700 ~/.ssh
    chmod 644 ~/.ssh/authorized_keys
    chmod 644 ~/.ssh/known_hosts
    chmod 644 ~/.ssh/config
    chmod 600 ~/.ssh/id_rsa
    chmod 644 ~/.ssh/id_rsa.pub
    chmod 600 ~/.ssh/github_rsa
    chmod 644 ~/.ssh/github_rsa.pub
    chmod 600 ~/.ssh/mozilla_rsa
    chmod 644 ~/.ssh/mozilla_rsa.pub


    Certbot and Letsencrypt

    For certbot and letsencrypt
    https://certbot.eff.org/lets-encrypt/centosrhel7-apache

    mysql -u [new_user] -p [database_name] < [file_name].sql
    Restore database dump file

    mysql -u [new_user] -p [database_name] < [file_name].sql
    

    Backup of a single database

    Backup a single database to a plain text file, containing the sql commands to restore the tables and their data

    mysqldump -u [user] -p [database_name] > [filename].sql

    Vi uses

    :[line-number]
    :set number (show line numbers) CTRL-SHIFT-G to show line
    /[search string forward]
    ?[search string backward]
    SHIFT-N -> next search

    next

    Leave a Reply

    Your email address will not be published. Required fields are marked *