Use ssh with private key public key authentication. Connect from wan.

procedure

Operation on the client

Make a key with PuTTygen on the client side. If you don't have PuTTygen, please install PuTTy.

Operation on the server

Format the public key you sent into a format that can be used by the server.

$ ssh-keygen -i -f key name.pub >> authorized_keys

Create a .ssh directory in / home / user name.

$ mkdir /home/user name/.ssh

Move the formatted public key to .ssh.

$ mv authorized_keys /home/user name/.ssh

Set access privileges for authorized_keys.

$ chmod 600 .ssh/authorized_keys

Set access rights for .ssh.

$ chmod 700 .ssh

With the above settings, you can now ssh connect using the key authentication method. From here, for added security, change the server settings to prevent password authentication and change the port.

Operation on the server

Open the ssh configuration file in an editor.

$sudo vim /etc/ssh/sshd_config

Disable password authentication.

PasswordAuthentication no

Change the port number in sshd_config.

#Port22
Port2000

Restart sshd

$service sshd restart

This completes the settings. When connecting from wan, use the port forwarding function of the router.

Log in from the client using the private key from PuTTy. For the private key, specify the path from the Auth field in the SSH of Category: Connection.

Where it gets stuck

I didn't realize I had to format my public key on linux and took a long time to set it up.

Reference site

Summary of procedure for making SSH connection with public key authentication method with PuTTY

Recommended Posts

Use ssh with private key public key authentication. Connect from wan.
How to generate a public key from an SSH private key
[SSH] About public key authentication and EC2
Pipenv install with ssh from Private Bitbucket Repository
How to set up public key authentication in ssh
[Amazon Linux 2] Change from public key authentication to password authentication
Remove ssh private key passphrase
Connect to centos6 on virtualbox with ssh connection from Mac
Log in to Raspberry PI with ssh without password (key authentication)
SSH public key authentication was set for Sakura VPS Cent OS 7.7
[Python] Use Basic/Digest authentication with Flask
Ssh connect to GCP from Windows
[Linux setting series] How to set public key authentication / ssh-keygen / ssh key / authorized_keys
Until you can borrow VPS with Conoha and authenticate public key with SSH
Use boto3 with temporary credentials with SAML authentication
Connect with mysql.connector with ssh tunnel in Python 3.7
Use Anaconda-Python installed with pyenv from openFrameworks
Use C ++ functions from python with pybind11
[Go] Use Open ID Connect with go-oidc
How to use SQLAlchemy / Connect with aiomysql