Tag: Linux

  • How to add or change the password (passphrase) of OpenSSH key?

    How to add or change the password (passphrase) of OpenSSH key?

    It’s possible you have earlier generated a ssh key without password/ passphrase. Later you found that for security reasons you wish to add a password to the key file.

    Let’s learn how to add password or passphrase to existing SSH Key. The method is also valid for changing the passphrase to the key. Use below command to do that.

    ssh-keygen -p -f /path/to/keyfile

    ssh-keygen man page

    -p Requests changing the passphrase of a private key file instead of
     creating a new private key. The program will prompt for the file
     containing the private key, for the old passphrase, and twice for
     the new passphrase.
     
    -f filename
     Specifies the filename of the key file.
     Example: ssh-keygen -p -f ~/.ssh/id_rsa

    Example:

    surya@x:~$ ssh-keygen -p -f /path/to/key
    Key has comment 'key'
    Enter new passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved with the new passphrase.
    

    This is how you can change or add the password to pre generated OpenSSH Keyfile.

  • How to find files on linux OS ( distributions )

    How to find files on linux OS ( distributions )

    find files on linux

    If you are working on Linux OS, finding files effectively always a tricky part.

    Like find files greater than 500 MB, find files which are created 2 days ago, find and delete all files recursively which are greater than specific date.

    Lets learn these simple linux tricks to work with files.

    How to find files or directory in Linux?

    For Files command: 

    find /path/to/directory -name "*.txt" -type f

    For Directory

    find /path/to/directory -name "nameOfDirectory" -type d

    In the above commands only type argument is changed from f to d. f represents for file and d represents for directory.

    How to find files which are greater than specific size?

    find /path/to/directory -type f -size +1024M

    How to find files which are created after number of days?

    find /path/to/directory -mindepth 1 -mtime +5 -size +700M

    How to delete files after finding files?

    Method 1:

    find /path/to/directory -mindepth 1 -mtime +5 -size +700M -delete

    mindepth is for level

    mtime for number of days

    size is for file size greater than or equal to.

    Method 2:

    find . -name "*.done" -type f -print0 | xargs -0 rm -f

    How to find files and set permission to 644 or 664?

    find . -type f -print0 | xargs -0 chmod 0644

    How to find all directory and set permission to 755 or 775?

    find . -type d -print0 | xargs -0 chmod 0755
    
    

    This is how you can work with find command. You can always check for man for more arguments.

  • How to decode CSR (Certificate Signing Request) ?

    How to decode CSR (Certificate Signing Request) ?

    What is CSR?

    Certificate Signing Request
    Certificate Signing Request is encrypted piece of code which is going to used for generating the SSL Certificate for your domain name.

     

    CSR contains the information about Country, State, Location, Organisation Name, Common Name ie Domain Name , Email Address and Public Key.

    Lets see how to extract the information from the CSR file?

    How to extract information from the CSR?

    surya@x ~/ » openssl req -in blog.suryaelite.com.csr -text -noout

    How to verify the signature of CSR?

    surya@x ~/ » openssl req -in blog.suryaelite.com.csr -noout -verify

    To which company certificate is issued to?

    surya@x ~/ » openssl req -in blog.suryaelite.com.csr -noout -subject

    How to extract Public Key from CSR?

    surya@x ~/ » openssl req -in blog.suryaelite.com.csr -noout -pubkey

    This is how you can extract the various information from the CSR file.