To generate a set of RSA keys with PuTTYgen
Now, you need to paste the copied public key in the file ~/.ssh/authorized_keys on your server.
mkdir ~/.ssh chmod 0700 ~/.ssh touch ~/.ssh/authorized_keys chmod 0644 ~/.ssh/authorized_keys
sudo vi ~/.ssh/authorized_keys
In PuTTY, you can create (and save) profiles for connections to your various SSH servers, so you don't have to remember, and continually re-type redundant information.
Now you can go ahead and log in and you will not be prompted for a password. However, if you had set a passphrase on your public key, you will be asked to enter the passphrase at that time (and every time you log in, in the future).
We will enable two-factor authentication in our ubuntu server. To implement that we are going to use multifactor authentication with Google Authenticator.
https://support.google.com/accounts/answer/1066447?hl=en
sudo apt-get update sudo apt-get install libpam-google-authenticator
$ google-authenticator Do you want authentication tokens to be time-based (y/n) y
If you can't see the full QR code in your putty screen, use the google url given, on your browser.
You will be prompted for some configurations.
Do you want me to update your "/home/thilina/.google_authenticator" file? (y/n) y Do you want to disallow multiple uses of the same authentication token? This restricts you to one login about every 30s, but it increases your chances to notice or even prevent man-in-the-middle attacks (y/n) y By default, a new token is generated every 30 seconds by the mobile app. In order to compensate for possible time-skew between the client and the server, we allow an extra token before and after the current time. This allows for a time skew of up to 30 seconds between authentication server and client. If you experience problems with poor time synchronization, you can increase the window from its default size of 3 permitted codes (one previous code, the current code, the next code) to 17 permitted codes (the 8 previous codes, the current code, and the 8 next codes). This will permit for a time skew of up to 4 minutes between client and server. Do you want to do so? (y/n) y If the computer that you are logging into isn't hardened against brute-force login attempts, you can enable rate-limiting for the authentication module. By default, this limits attackers to no more than 3 login attempts every 30s. Do you want to enable rate-limiting? (y/n) y
sudo vi /etc/pam.d/common-session
auth required pam_google_authenticator.so nullok
sudo vi /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
sudo service ssh restart
Try to ssh to the server from a new terminal. It will ask for the verification code.
Note: This tutorial was based on training content of APNIC, NSRC and SANOG