2021/12/15

Easy connection to a remote server using SSH (Linux & macOS)

data_encryption
Table of content
  1. What is SSH and why it is used
  2. How to use SSH to connect to a remote server with a private key
  3. How to use ssh-agent to store your keys and passwords for easy logins

Requirements:

  • A Linux or macOS distribution installed on your computer
  • Access to a user with root privileges

1. What is SSH and why it is used?

SSH stands for Secure Socket Shell. It’s a protocol that allows users to connect in a secure way to remote servers. Although strong passwords alone give basic protection from security threats, encrypted data communication is necessary for a safe connection to servers. In addition, SSH can be used for:

  • Executing commands remotely and setting up a server
  • Transferring any kind of file
  • Managing access to a server for different users

SSH establish a secure connection with the help of a set of asymmetric encryption keys. Two keys are generated for SSH: a public key and a private key.

  • The role of the public key is to encrypt the data. It is configured inside the remote server.
  • The private key is used to decrypt the data that has been encrypted by the public key: it is given to the users to allow them to connect to the server.

Hence the terminology, the public key can be made public whereas the private should be kept private.

2. How to use SSH to connect to a remote server with a private key

Straight to the point: if it is only for a one time connection, enter the following command into your terminal:

$ ssh -i ssh_key_path/ssh_key Username@Hostname_or_IP

Where:

  • ssh_key_path is the path of the directory containing your private key
  • ssh_key is the filename of your key
  • Username is the name of the user inside the remote server
  • Hostname_or_IP has to either be the hostname or the IP of the remote server

The ssh command should be installed by default on your system. Please note that root privileges are required to execute this command. Moreover, you might be prompted to enter the password for the key after executing this command. If the key password is unknown to you, you need to verify it with the provider of your key.

3. How to use ssh-agent to store your keys and passwords for easy logins

If you will frequently connect to the remote server by SSH, you may want to configure ssh to store your keys and passwords. This way, you won’t need to specify your private key and its password at each connection. Here is how it is done:

$ ssh-agent $BASH
$ ssh-add ssh_key_path/ssh_key

If there is a password attached to your private key, you will be prompted to input it.

If you obtain the error message “WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0644 for ‘ssh_key_path/ssh_key’ are too open.”, you can resolve this permission with the following simple command:

$ chmod 400 ssh_key_path/ssh_key

Then execute once more the ssh-add command and you will become able to simply access the remote server with your username, host information and no password:

$ ssh Username@Hostname_or_IP

関連記事


icon-loading

ハルシネーションは敵か味方か – 創造性を加速するAIの取扱説明書

生成AIのハルシネーションを正しく理解し、temperature・top_p・プロンプトで出力を制御する実践法を解説。gpt-5の抑制傾向、人間の創造性やSFが技術革新に与えた影響、ポストイットとペニシリンの発明エピソードまで網羅する。

icon-loading

LLMを変えた分岐点:「Attention Is All You Need」とTransformerの前後比較

論文「Attention Is All You Need」が提案したTransformerは、AIの文章理解と生成を根本から変えた。本記事では、その仕組みと前後比較をビジネス視点で解説し、なぜ今この技術を知ることが戦略的メリットになるのかを明らかにする。

icon-loading

イーロン・マスク第一弾 – テスラの自動運転戦略:ウェイモとの決定的な違いとLiDAR不要論

イーロン・マスク率いるテスラの自動運転戦略を解説。ウェイモとのセンサー構成の違い、LiDAR不要論、トップダウン経営による大胆な方針転換、そして完全AI制御への移行までを網羅。長期的にはロボット「オプティマス」との連携を視野に入れたテスラが有利とする理由を探る。

icon-loading

10km先のエロ本からGrokのSpicy Modeへ – 性欲がテクノロジーを進化させる

性欲は人類最強の技術普及ドライバーである。VHS普及からGrokのSpicy Modeまで、アダルトが牽引してきたイノベーションの歴史と、AI時代における性欲とテクノロジーの新たな関係性について、IT企業CEOが実体験を交えて解説。