Skip to content

SSH password less login

AnsuDennis edited this page Sep 2, 2020 · 1 revision

SSH password less login setup

Without below setup u will have to use username password whenever u connect to server

Use ssh-keygen command to generate rsa key pair. This will generate private and public key dennis@test-docker:$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/dennis/.ssh/id_rsa): Created directory '/home/dennis/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/dennis/.ssh/id_rsa Your public key has been saved in /home/dennis/.ssh/id_rsa.pub The key fingerprint is: SHA256:24I2alsXbTMD/MYLUK+ol+vLwSotQDAuIM8Oedm7XB4 dennis@test-docker The key's randomart image is: +---[RSA 3072]----+ | . | |= o . | |== o . o . | |+o= . o * | |o+ .. S X | |. . .oEo B = | | . o.+X.+ o | | o =B.= . | | ++o=. | +----[SHA256]-----+ dennis@test-docker:$ ls -la total 32 drwx------ 4 root root 4096 Jul 11 16:10 . drwxr-xr-x 20 root root 4096 Jul 11 15:37 .. -rw------- 1 root root 1079 Jul 22 23:10 .bash_history -rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc -rw-r--r-- 1 root root 161 Dec 5 2019 .profile drwxr-xr-x 3 root root 4096 Jul 11 15:47 snap drwx------ 2 root root 4096 Jul 11 15:46 .ssh -rw------- 1 root root 1235 Jul 11 16:09 .viminfo

.ssh directory should have 700 permission and the file should have 600 permission

dennis@test-docker:$ cd .ssh dennis@test-docker:/.ssh$ ls -la total 16 drwx------ 2 dennis dennis 4096 Sep 1 14:01 . drwxr-xr-x 5 dennis dennis 4096 Sep 1 14:01 .. -rw------- 1 dennis dennis 2602 Sep 1 14:01 id_rsa -rw-r--r-- 1 dennis dennis 572 Sep 1 14:01 id_rsa.pub dennis@test-docker:~/.ssh$

Now we need to append the public key from . pub file to

root@kube-ub-node2:# cd .ssh root@kube-ub-node2:/.ssh# ls -la total 8 drwx------ 2 root root 4096 Jul 11 15:46 . drwx------ 4 root root 4096 Jul 11 16:10 .. -rw------- 1 root root 0 Jul 11 15:46 authorized_keys root@kube-ub-node2:~/.ssh# vi authorized_keys

Once the public key is copied connect to target server using ssh

dennis@test-docker:~$ ssh root@192.168.41.135 The authenticity of host '192.168.41.135 (192.168.41.135)' can't be established. ECDSA key fingerprint is *********************************************. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.41.135' (ECDSA) to the list of known hosts. Welcome to Ubuntu 20.04 LTS (GNU/Linux 5.4.0-42-generic x86_64)

System information as of Tue 01 Sep 2020 02:05:12 PM UTC

System load: 0.29 Users logged in: 1 Usage of /: 32.1% of 23.99GB IPv4 address for docker0: 172.17.0.1 Memory usage: 37% IPv4 address for ens33: 192.168.41.135 Swap usage: 0% IPv4 address for tunl0: 10.244.239.64 Processes: 265

  • Kubernetes 1.19 is out! Get it in one command with:

    sudo snap install microk8s --channel=1.19 --classic

    https://microk8s.io/ has docs and details.

76 updates can be installed immediately. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable

The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

root@kube-ub-node2:# hostname kube-ub-node2 root@kube-ub-node2:# exit logout Connection to 192.168.41.135 closed.

Now try to connect and copy a file using scp command

dennis@test-docker:~$ scp abcd root@192.168.41.135:/tmp/ abcd 100% 0 0.0KB/s 00:00

Verify that the file is copied to target server

root@kube-ub-node2:~/.ssh# cd /tmp root@kube-ub-node2:/tmp# ls -trl total 20 drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-timesyncd.service-E8W88g drwx------ 2 root root 4096 Aug 31 14:06 vmware-root_795-4257200573 drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-resolved.service-OWdRQe drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-logind.service-FdySrf drwx------ 3 root root 4096 Aug 31 14:06 snap.lxd -rw-r--r-- 1 root root 0 Sep 1 14:06 abcd

Now try to connect and copy a file using rsync command

dennis@test-docker:~/unix$ rsync -avzh file root@192.168.41.135:/tmp sending incremental file list file

sent 136 bytes received 35 bytes 114.00 bytes/sec total size is 34 speedup is 0.20

Verify that the file is copied to target server

root@kube-ub-node2:/tmp# ls -ltr total 24 drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-timesyncd.service-E8W88g drwx------ 2 root root 4096 Aug 31 14:06 vmware-root_795-4257200573 drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-resolved.service-OWdRQe drwx------ 3 root root 4096 Aug 31 14:06 systemd-private-0033a757c0944ded8a3af0708556d37c-systemd-logind.service-FdySrf drwx------ 3 root root 4096 Aug 31 14:06 snap.lxd -rw-r--r-- 1 root root 0 Sep 1 14:06 abcd -rw-rw-r-- 1 dennis dennis 34 Sep 1 14:39 file root@kube-ub-node2:/tmp#

Clone this wiki locally