Tuesday, March 22, 2022

How to ssh pipe copy files from remote to local compressed

ssh  john@192.168.1.49  "cd ~/Documents && tar -cf - assignments/ | gzip -9"  >  assignments.tar.gz


# syntax explanation

ssh    username@remoteIP     "command string"


Labels: , , ,

Saturday, August 28, 2021

HOWTO - Git server setup on ubuntu

ref:  https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server


1. create 'git' user and group



    $ sudo adduser git


2. create git users



    $ sudo useradd -M  adam # not create home directory

    $ sudo passwd  adam

    $ sudo usermod -G git  adam


    $ which git-shell


in /etc/passwd, replace /bin/bash with  /usr/bin/git-shell    # git-only ssh login



3. handle ssh keys


    $ su git
    $ cd
    $ mkdir .ssh && chmod 700 .ssh
    $ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys 

    $ cat /tmp/id_rsa.adam.pub >> ~/.ssh/authorized_keys


4. create new project



    $ mkdir -p  /home/git

    $ chmod g-w /home/git        # make sure group has no write access

    $ cd /home/git

    $ git init --bare test.git

    $ chmod -R git:git test.git/ # double-check

    $ chmod -R 775 test.git/



# check project from user side


    $ git clone adam@serverip:/home/git/test.git

    $ cd test

    $ git remote -v

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: , ,

Tuesday, May 08, 2018

HOWTO connect to GIT repo setting up SSH credential, avoid typing password


git pull from bitbucket or github, requires user account credential, either password, or ssh key, if didn't use keychain or caching the password.

steps:

0) of course you need ssh

1) in folder ~/.ssh
    ssh-keygen
    # to generate a key pair - private key & public key

2) keep private key private (obviously), add to your ssh agent as identity
    ssh-add ~/.ssh/mykey

3) set up public key remotely, locate ssh credential, click "add key"
    copy and paste the text of public key file to, eg. bitbucket, add key text input field.

done

Labels: , , , , , , ,