Saturday, July 31, 2021

Mac/Linux/Ubuntu to convert PDF to JPG

 

ref: https://stackoverflow.com/questions/43085889/how-to-convert-a-pdf-into-jpg-with-command-line-in-linux

        

# using  Image magic


    $ convert -density 300 -quality 100 input.pdf prefix.jpg     


# will give files  prefix-0.jpg, prefix-1.jpg, prefix-2.jpg ...


Labels: , , , , ,

Saturday, July 17, 2021

ubuntu-to-ubuntu ssh connection

ubuntu has pre-installed ssh client but not server.


ref:  https://ubuntu.com/server/docs/service-openssh


###############

# ENABLE SSH #

###############


To have the REMOTE ubuntu accepting ssh connection, install ssh server:


    $ sudo apt update

    $ sudo apt upgrade 

    $ sudo apt install openssh-server


The SSH service is automatically started.


In case ssh config changes are needed, for example, using port 5000 instead of default port 22, modify the config file:


    $ sudo nano /etc/ssh/ssh_config


then restart the server


    $ systemctl restart ssh.service

or

    $ systemctl restart sshd

or 

    $ sudo service sshd restart


LOCAL ubuntu for the first time ssh'ing to a new server, command prompts to confirm fingerprint.  

For comparison, show the fingerprint on the SSH server side (REMOTE ubuntu):


    $ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub



###################

# SKIP PASSWORD #

###################


If frequently SSH to a server, one could set up SSH key to avoid typing password for connection.

1. LOCAL, generate a key pair - private key and public key


    $ ssh-keygen -f /path/to/myserver.ppk


2. copy public key from LOCAL to REMOTE


    $ scp -i /path/to/myserver.ppk.pub  user@REMOTE


    # above command create or append to REMOTE   /home/user/.ssh/authorized_keys


3. connect with no password


    $ ssh -i /path/to/myserver.ppk  user@REMOTE


4. (optionally) disable password login

    With the ssh key set up properly, now we can disable regular password login.

    a. change in /etc/ssh/sshd_config, from 


        #PasswordAuthentication yes

        to

        PasswordAuthentication no


    b. restart service


        service ssh restart


#############################

# OTHER settings in sshd_config #

#############################

https://askubuntu.com/questions/869945/how-to-disable-password-and-root-ssh

  • Deny all root login
  • Deny all password logins for all users
  • Allow other users with other authentication methods (publickey)

This is achieved using below configuration options:


    PermitRootLogin no
    PasswordAuthentication no
    ChallengeResponseAuthentication no


Then restart service


        service ssh restart


#################

# X11 Forwarding  #

#################

    1. REMOTE side to enable X11 Forwarding in ssh_config

    2. LOCAL side


            ssh -X -i /path/to/private_key  user@IP  "gvim ~/dummy.txt"


    or to remotely run local script with parameters:


        ssh user@REMOTE 'bash -s' < test.sh true true true



Labels: , ,

Sunday, July 11, 2021

Python virtual environment in MacOS

On mac osx, default python is version 2, to support system pre-installed packages.


To try python3 environment, one option is using virtual environment, which allows installing different packages in isolated environment.


ref: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

With python2, install virtualenv

With python3, built-in module is    'venv'



    $ python3 -m pip install --user --upgrade pip     # update pip3


    $ python3 -m pip --version    # check version 


## assume venv for python3

# reuse  ~/.virtualenv  as the root for all new environments


    cd ~/.virtualenv


# (one time only) create new environment for python3


    $ python3 -m venv  py3


## use of environment from now on

# 1) using environment


    $ source py3/bin/activate


    $ which python        # should be within env now


# now can install diff python3 packages for testing


# 2) leaving venv


    $ deactivate



Labels: , , , ,

Git shallow clone and unshallow

Some git project is huge.  You want to clone but not care about the history, or only interested in the most recent stable version tagged.

Option 1, in github, select specific version tag in drop box, then click 'code' and download source as a zip file.

Option 2, git clone just that particular commit:


    $ git clone --depth 1 --b v3.5.6 {git_url} 


# --depth 1 implies --single-branchjust 1 commit, not all history on that branch.  Or, explicitly get more branches


    $ git fetch --depth 1 --no-single-branch {git_url}

    # 2021 Oct:    above command no longer works in git.

    # new method: 

    # modify .git/config, under [remote "origin"]

    # change fetch to

    #     fetch = +refs/heads/*:refs/remotes/origin/*

    # then,     git fetch --depth 1

    # (for details, see  https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches)


Above command gives you one commit, no history, no checkout branch.


    $ git branch       # nothing

    $ git branch -r    # also empty

    $ git branch -a    # all, check both locally & remotely


Now say, you want to get MORE history


    $ git fetch --depth=100


or get ALL history


    $ git fetch --unshallow


What if I want to get checkout another branch, for example, the master code now?


    $ git fetch  {git_url}  master:master

    $ git checkout master


# check out another branch with just one commit


    $ git fetch --depth 1 origin devel:devel



Labels: , ,

Saturday, July 10, 2021

mx linux get version number

# distribution info


    lsb_release -a        # all

    lsb_release -r        # release

    lsb_release -c        # codename:  buster    

    lsb_release -d       #  description


    cat /etc/mx-version

    MX-19......



# kernel and machine info 


    uname -a        # all

    uname -m        # machine    'x86_64'

    uname -s        # system        'linux'


Labels:

Sunday, July 04, 2021

ubuntu RAID 5 or 6 with missing drive(s)

some RAID configurations allow missing drives, for example, 5 or 6 or up.


say, raid 5 with 1 drive missing:


    $ cat /proc/mdstat


if mdadm drive is detected but inactive, stop it.


    $ sudo mdadm --stop /dev/md5


indicate using only 2 drives for read only.


    $ sudo mdadm --assemble --readonly /dev/md5 /dev/sdc1 /dev/sdd1


first time likely got error, force it


    $ sudo mdadm --run /dev/md5

    $ ls /dev/md5 


now exist


    $ sudo mount /dev/md5 /mnt


drive now readable.



when done


    $ sudo umount /mnt

    sudo mdadm --stop /dev/md5





Labels: , ,