HOME BLOG

Archive for September, 2020

How to request sensitive details in Python without displaying the input on the screen

Posted on: September 26th, 2020 by Olu No Comments

Hi folks,

Here’s a short code snippet that demonstrates how to request sensitive information from a Python application without displaying the details on screen as the user enters it. The tool to use is a library called getpass as well as the subprocess library. Here it is.

 

import subprocess

info_process = subprocess.run([
'python', '-c', 
"print(import('getpass').getpass('Enter the details here'))"
], stdout=subprocess.PIPE)

details = info_process.stdout.decode('utf-8').strip()

That’s all for now. Happy coding

How to fix issue of “’” showing on page instead of “ ‘ ” in gVim in Windows

Posted on: September 26th, 2020 by Olu No Comments

Hi folks,

Recently I experienced an issue where when I opened a file using my favourite editor gVim in Windows and found to my utter bewilderment that the “’” character was showing instead of “ ‘ ”. I’ll quickly talk about how to fix such problem.

First, what’s the cause? The cause is that the editor isn’t using UTF-8 encoding. It might be using ISO-8859-1/Windows-1252. So, to fix it, update gVim to use UTF-8. Here’s how to do that.

Open your _vimrc file and add the following lines

 

set encoding=utf-8
set fileencoding=utf-8

Save and close the file. That’s it. Your apostrophe characters should now display correctly. Happy editing.

Sources:

“’” showing on page instead of “ ‘ ”. stackoverflow. https://stackoverflow.com/questions/2477452/%C3%A2%E2%82%AC-showing-on-page-instead-of

Set encoding and fileencoding to utf-8 in Vim. stackoverflow. https://stackoverflow.com/questions/16507777/set-encoding-and-fileencoding-to-utf-8-in-vim

SSH Login without password from Windows to Linux

Posted on: September 20th, 2020 by Olu No Comments

Your aim

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from Windows host A / user a to Linux Host B / user b. You don’t want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it

First log in on A as user a and generate a pair of authentication keys. Do this using Git Bash. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password: 

Finally append a’s new public key to b@B:.ssh/authorized_keys and enter b’s password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

 

Source:

 

SSH login without password. http://linuxproblem.org/art_9.html

How to add rsync to Git Bash in Windows 10

Posted on: September 20th, 2020 by Olu No Comments

Download the package: http://www2.futureware.at/~nickoe/msys2-mirror/msys/x86_64/rsync-3.1.2-2-x86_64.pkg.tar.xz

 

Launch Git Bash and change to the download location.

 

Extract the archive using coommand:

 

tar -xf rsync-3.1.2-2-x86_64.pkg.tar.xz

 

You will get a folder usr.

 

Move usr/bin/rsync.exe to C:\Program Files\Git\usr\bin

 

Source:

How to Add rsync to Git Bash for Windows 10. https://gist.github.com/hisplan/ee54e48f17b92c6609ac16f83073dde6