Wednesday, 24 November 2021

Set Up SSH Keys

How To Set Up SSH Keys:
1) Creating the Key Pair
[root@centos8 ~]# ssh-keygen -t ed25519

Note: if you are on an older system that does not support creating ed25519 key pairs, or the server you’re connecting to does not support them, you should create a strong rsa keypair instead:
[root@centos8 ~]# ssh-keygen -t rsa -b 4096






















This changes the -t “type” flag to rsa, and adds the -b 4096 “bits” flag to create a 4096 bit key. SSH keys are 2048 bits by default, 4096 bits for a more hardened key.
 ~/.ssh/id_rsa: The private key. DO NOT SHARE THIS FILE!
~/.ssh/id_rsa.pub: The associated public key. This can be shared freely without consequence.
2) Copying the Public Key to Your Server
[root@centos8 ~]# ssh-copy-id root@192.168.1.2

In target server, vi /root/.ssh/authorized_keys

Using PuTTYgen on Windows to generate SSH key pairs:








































Save the public key into target server authorized_keys
eg. [root@centos7 ~]# vim /root/.ssh/authorized_keys



In Solar-Putty:






























Allow root ssh login with public key authentication only:





SSH Keys for Users
1) Login as user
2) Change to user home directory, eg. /home/William
3) Create .ssh > create authorized_keys inside .ssh > update public key
[william@centos7 ~]$ mkdir .ssh; chmod 700 .ssh; cd .ssh; touch authorized_keys; chmod 600 authorized_keys; vim authorized_keys

4) [root@centos7 william]# vim /etc/sudoers
william ALL=NOPASSWD: ALL
 
In Putty:


























Tuesday, 16 November 2021

Connect as root using WINSCP

How to connect as root using WINSCP

Refer: https://blog.jamesbayley.com/2014/01/28/how-to-connect-as-root-using-winscp/

In my previous post I noted that I had not succeeded in in connecting to a linux machine as root using WINSCP when using the bitnami virtual machine.

My development implementation works, so I have progressed to using the cloud hosted bitnami instance. This comes with public key access rather than password access. This actually make it easier to connect.

  1. Download your private key, if using bitnami use the cloud console, if using AWS use the AWS console. Store it with no spaces in the file name.
  2. Optionally put it into your Pageant keystore
  3. Verify that you can connect using PuTTY

You now have two choices, you may use the SFTP protocol or the SCP protocol. My experience shows that connecting with SCP is easier.

USE the SCP protocol (preferred)

  1. Test connecting with WINSCP using using the SCP protocol and the bitnami (low priviledge user) and your private key.
  2. On the Advanced tab of WINSCP specify the Shell to be
    i) sudo su-



Use the SFTP protocol

  1. Test connecting with WINSCP using the SFTP protocol using the bitnami (low priviledge user) and your private key.
  2. Find the location of the sftp server, you will enter this into WINSCP later
    [root@test /]# locate sftp-server




  1. On the Advanced tab of the WINSCP specify the sudo -s command to run the server as su. This works because you are using PKI and are not asked to provide a password when you sudo.
    i) sudo su -c /usr/libexec/openssh/sftp-server or sudo -s /usr/libexec/openssh/sftp-server