Sujith's Blog

How to manage passwords

In recent times, an individual’s usage of multiple online platforms or services has increased exponentially. More often than not, we end up using the “Forgot Password” feature, which becomes a tedious process, especially when we have to do it over and over again. I was looking for a safe and secure way to store and manage these passwords.

Recently I came across this open source password manager ‘pass’. It is using GPG encrypted files to store passwords. And pass allows me to connect it with a git repo to keep a track of it and to save it in a central location.

pass can use your existing GPG key for encryption or it can generate one for you. If you don’t have a GPG key, follow this to create one.

  • Install pass

    Use your favourite package manager to install pass,

    from MacOS brew install pass

    or from Ubuntu/Debian sudo apt-get install pass.

  • Use existing GPG key with pass

    Initialise pass with your GPG key pass init "<your GPG key ID>".

  • Adding your first password to pass

    Use insert command to add new password.

    pass insert email/hotmail

  • Reading password from pass

    Just use pass command to get a list of your passwords.

    and use pass <path to a specific password> to see a specific password. You can also get one password into clipboard using pass -c email/hotmail

  • Integrate with a git repo and track your passwords

    Create a git repo(preferably private) in one of the git repo hosting provider (GitHub/BitBucket/Gitlab), may be the one less exposed to other apps and integrations for security reasons.

    Now use pass git init to initialize git repository for pass, and add the git repo url to pass using pass git remote add origin <repo URL>. Now pass creates a git commit for each change you make to your passwords.

Next steps

pass is available in mobile devices as well. I use the community maintained Android app Android-Password-Store. You can use Paperkey to get your GPG key printed on a paper, and use it when you have lost access to your computer, to restore it to a new device.

How to host multiple website on a single server with Apache

If you are a web developer using Apache web server for hosting, then this is for you. You might have faced scenarios where you have to host multiple websites in the same server. For instance if you want to host example.com and sujith.com in a server. In Apache, we can use virtual hosts to do this.

I am assuming that you have already installed Apache webserver.

As a first step, keep the content of sites in /var/www/example.com/html, /var/www/sujith.com/html locations.

Now we have to create a virtual hosts file for both the sites in /etc/apache2/sites-available/ directory.

for first domain

Create the virtual host file from 000-default.conf.

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

Open the created file in your favorite text editor

$ sudo nano /etc/apache2/sites-available/example.com.conf

Next you have to modify the default configuration like this:

 <VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/html
    ErrorLog ${APACHE_LOG_DIR}/example.error.log
    CustomLog ${APACHE_LOG_DIR}/example.access.log combined
</VirtualHost> 

for second domain

Create the virtual host file from 000-default.conf.

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/sujith.com.conf

Open the created file in your favorite text editor.

$ sudo nano /etc/apache2/sites-available/sujith.com.conf

Next you have to modify the default configuration like this:

 <VirtualHost *:80>
    ServerAdmin admin@sujith.com
    ServerName sujith.com
    ServerAlias www.sujith.com
    DocumentRoot /var/www/sujith.com/html
    ErrorLog ${APACHE_LOG_DIR}/sujith.error.log
    CustomLog ${APACHE_LOG_DIR}/sujith.access.log combined
</VirtualHost> 

Now enable the sites

$ sudo a2ensite example.com.conf $ sudo a2ensite sujith.com.conf

Once the sites are enabled, you have to map both sujith.com and example.com to the IP of this server in DNS settings of the domains.

You can also test this by manually adding an entry like this to /etc/hosts

  127.0.0.1 sujith.com
  127.0.0.1 example.com
  ## use server's IP address if you are testing from any other system.

Now you can test this by visiting http://example.com and http://sujith.com.

How to move cursor to the last edited location in Vim

For moving or jumping cursor to the last edited locations in Vim use g, and g; commands in normal mode.

g, moves cursor forward or to the newer positions in change list, g; moves the cursor to the older location or positions in the changelist.

Both of these operations can accept count as an optional argument, which will take cursor to the n-th position in the change list.

To know more about changelist use :help changelist.

How to set transparent background for iTerm2 in full screen mode on a Mac

I was trying to set transparent background to iTerm2, but when I switched to full screen mode, the background was again black.

Recently, I came across the following settings in the iTerm2, which allow us to make the background transparent in full screen mode:

  1. Open your iTerm2-> Choose Full screen window style in Open profiles -> Edit profiles -> Window -> Stylesettings.
  2. Now un-check the Native full screen windows in General settings of iTerm(not the profile).
  3. Now you can choose the level transparency in Open profiles -> Edit profiles -> Window settings.
  4. Now check the iTerm2 in full screen mode, You will be able to see the icons and apps in the background.

Now you can use the system-wide hotkey mentioned in Keys settings/Preferences of iTerm to show/hide iTerm.

How to select a range conditionally in vim

I use norm command along with visual selection to perform normal-mode operations on several lines in one go.

Now how to do the range selection based on a condition without switching to Visual selection mode ?

For example, if we want to append a comma(,) to each line till the next blank line. Let’s do this without a visual selection, :.,/^$/-1 norm A, this command will do the above task in one-go.

Command explanation

  • : : the starting of command-mode.
  • . : the first part of the range selection, were . indicates the current line in range selection
  • , : is the separator used between start and end of the range.
  • /^$/ : is the pattern for blank line, were ^ is the start and $ end of line.
  • -1 : -1 indicates the line before, when it si combined with pattern the line before blank line.
  • norm A, : performs normal mode operation A, which will append a , to the end of line.

Now you can use any patterns specified in Ranges doc to select/specify the Range, this blank line pattern is just an example.

This conditional range selection is very useful while recording macro spanning over multiple lines.

Read more about Ranges.