Monday, October 18, 2021

Connect to a wifi by scanning a QR code in Linux

There is a project in github, that contain a script to easily accomplish this task. The project is called wifi-qr by kokoye2007. It can be cloned here.


To use the script, we need to clone the project from github.

$ git clone https://github.com/kokoye2007/wifi-qr

Once cloned, go into the project directory.

$ cd wifi-qr

To scan a QR code, and connect to the wifi information contained in the code 

$ ./wifi-qr s

A camera interface will be displayed. Show our wifi QR code to the computer's webcam, and the script will read the QR code and automatically connect to the wifi using the information in the QR code.


Apart from scanning QR code and connecting to the wifi, this script has a lot more functions. You can read about all the functions here. Thank you to kokoye2007 for this excellent tool.

 

Friday, October 15, 2021

Scanning QR Code in Ubuntu Linux

To get the information from a qr code, first and foremost, we need to save the qr code as a file. One of the way is to use a webcam, and an app called cheese to take picture using the webcam. Then we need to install zbar-tools to extract information from the qr code file. 


Install cheese

$ sudo apt update; sudo apt install cheese -y

Install zbar-tools

$ sudo apt install zbar-tools -y


Then, take a picture of the qr code using cheese via our webcam.


Once we have the qr code saved in a file, use zbarimg to extract the information from the qr code

$ zbarimg Downloads/frame.png 

QR-Code:https://www.linuxwave.info

scanned 1 barcode symbols from 1 images in 0.04 seconds


You can see that in the above output, that the qr code contain a url to this website.

 


 


Tuesday, October 12, 2021

Create QR code for wifi in linux

To easily share wifi credentials, a QR code can be used. A QR code can contain the information of the wifi, and can be scanned easily using any qr code reader in mobile phones. To make the QR code, we need a tool called qrencode.


First, prepare the wifi information using below format:

WIFI:S:{SSID name of your network};T:{security type - WPA or WEP};P:{the network password};;

For example, my wifi SSID is mysecurewifi, it is using WPA, and the password is mysecurewifipassword. 

 WIFI:S:mysecurewifi;T:WPA;P:mysecurewifipassword;;


Install qrencode

$ sudo apt update && sudo apt install qrencode


Provide the above information against qrencode command to generate a qr code image file called mywifi.png

$ qrencode -o mywifi.png '

WIFI:S:mysecurewifi;T:WPA;P:mysecurewifipassword;;'

 

If the generated image is too small, you can increase the size of the dot pixel using '-s' option

$ qrencode -o mywifi.png -s 10 'WIFI:S:mysecurewifi;T:WPA;P:mysecurewifipassword;;'


Share the file to anyone, or print it for the people who would like to use your wifi. 

Cheers! 

Thursday, September 30, 2021

Accessing android phone via ssh using termux

The ability to access your phone remotely is very useful. I frequently used this technique to copy files to and from my phone and checking my battery status while the phone is charging without actually holding the phone.

First and foremost, we have to install termux. You can install it from google playstore by clicking here


Once installed, fire up termux, and install openssh:

$ pkg install openssh

Then, create a password for the default user. The default user is u0_a274.

$ passwd

Then, launch an sshd daemon using below command to start openssh server in the phone, on port 1234 (the port can be any number above 1000).

$ sshd -p 1234

Check your ip address. using below command.

$ ip address 

Let's say our phone's ip address is 192.168.0.179. Make sure your desktop/laptop is connected to the same network as the phone's wifi connection. Fire up a terminal, and ssh to the ip address.

$ ssh u0_a274@192.168.0.179 -p 1234 



Congratulations, you are now connected to your phone, via ssh.

 

Monday, September 6, 2021

Enabling passwordless ssh for Synology DSM version 6

Synology DSM 6.0 does not allow, let alone passwordless ssh by default. In order to enable that, so that we can have automated backup to Synology NAS, below are the steps:

1. Enable User Home in User  Advanced


 
2. Enable SSH in "Terminal & SNMP"  Terminal


3. (Recommended) Create a user, and add the user into administrator group by going to User → Create. As an example, I created a user called dbbackup.



4. Change permission of the user's home directory to 755. You can do this by ssh'ing into synology as admin, and run below command
$ ssh administrator@synology-ip
$ sudo chmod 775 /var/services/homes/dbbackup 

$ exit 


5. Ssh into synology as your new user. Edit below lines in /etc/ssh/sshd_config, and save the file.
$ ssh dbbackup@synology-ip
$ sudo vi /etc/ssh/sshd_config
...
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
ChallengeResponseAuthentication no
...
6. Restart sshd service
$ sudo synoservicectl --restart sshd

7. Exit from synology shell, and create a pair of ssh key in client machine, and press enter for all the questions

$ ssh-keygen

8. Transfer the public key into synology

$ ssh-copy-id dbbackup@synology-ip

9. Test you ssh connection to synology. You should be able to ssh without password into synology.

$ ssh dbbackup@synology-ip