Using SSH without password

Using SSH often to login to remote systems? Sick of entering your password every few minutes? Consider logging using public key authentication.

What is this?

This authentication method uses 2 keys: private and public. Let’s use example:

  • S is some remote server
  • C is your laptop

The public key is put on server. It can be shared with anyone, it is of no use to anyone except the owner of the private key.

The private key is kept in safe place on laptop. During authentication server S verifies whether the secret key from C matches the public key on S. If so, user is allowed to log in. It is important to remember, keeping the private key secret is just as important as guarding your password.

Preparation

Simpler than it used to be… To generate the new key pair:

and follow defaults. There will be a warning if the key already exists. For simplicity don’t specify a password (I will write how to use a password protected key without having to type too much another time).

Now, to copy the public key to remote sever run:

Enter the password once more, and try:

Congratulations! And remember to protect the key!

Python profiling

Introduction

Is your python script running slow? Fear no more! Just follow these few steps, and you should be able to pinpoint the culprit.

There are many ways to do this, this is the setup I use for quick profiling.

Prerequisites

  • pyprof2calltree: pip install pyprof2calltree
  • kcachegrind:
    • Debian/Ubuntu: apt-get install kcachegrind
    • Redhat/Centos: yum install kcachegrind

Collecting profiling data

The test run of the script should be with not too small, not too large amount of data. In my test runs I usually aim for about 10-20 seconds: it’s usually enough to get useful data without waiting too much. Make sure this is appropriate for you. It’s easiest if the script is runnable without any user interaction, then just:

Where (change as appropriate):

  • profile.dat will store the execution profile
  • test.py is the python script

Visualizing results

Sometimes it does not work (I saw it on a centos system), then try to do it in 2 steps:

It may be overwhelming at first, but there are enough views to finally figure out what is what. Just play a bit with it!

Tips

  1. When using libraries the graphs will quickly get too detailed (as they show the internal library details). There are options to limit this if it get’s too distracting
  2. Too complex code may get confusing for kcachegrind. If so, try to profile a simpler script with just just as little of the bottleneck code as necessary.