Infrastructure 2018-09-18

SSH Connection Setup Memo

Implement secure SSH key-based authentication with proper sshd configuration and permission management for remote servers.

Read in: ja
SSH Connection Setup Memo

Overview

A memo on how to set up SSH connections.

Preparation

Connect to the server and create a user belonging to the wheel group.

Steps

Host Side

In ~/.ssh/, use ssh-keygen to create a public key and a private key. Here, the public key is created as id_rsa.pub and the private key as id_rsa.

Copy the contents of the public key.

Create a config file in ~/.ssh/.

Ex.

Host bmf
 HostName 123.45.679.012
 User bmf
 Port 22
 IdentityFile ~/.ssh/id_rsa

Server Side

If ~/.ssh/ does not exist, create the directory. Set the permission to 700. mkdir .ssh && chmod 700 .ssh

Next, create a file named authorized_keys in ~/.ssh/. Set the permission to 600. Paste the contents of the public key into authorized_keys.

Then adjust the settings in /etc/ssh/sshd_config. Adjust the following settings:

Check if the port number used for SSH connection is open. firewall-cmd --list-all

If not open, open it. firewall-cmd --permanent --zone=public --add-port=22/tcp

Reload.

firewall-cmd --reload

Try Connecting

ssh bmf

Tags: ssh sshd
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles