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ボーイフレンドを返して!」GPT-5より劣るGPT-4oが愛される理由

GPT-5登場で起きた#keep4o運動の衝撃。4,300人が署名し24時間で旧モデル復活という異例事態から見える現実とは?「デジタルラブレター」「AIボーイフレンド」と表現するユーザーたち。IT企業CEOが語る技術者の本音vs感情AI需要のギャップ、B2BとtoCでの使い分け戦略、AIが人間に近い役割を果たす時代の到来。

icon-loading

イーロン・マスク第二弾 – 映像で学ぶロボット「オプティマス」が加速する進化の未来

テスラが開発するヒューマノイドロボット「オプティマス」は、自動運転と同じカメラ学習基盤で進化を加速する。家庭や工場でのデータ収集により能力を向上させ、Xの生成AI「Grok」と連携することで自律的知能端末へと進化する、イーロン・マスクの統合AI戦略を解説。

icon-loading

AIが不倫情報で人を脅迫:Claude Opus 4が見せた恐ろしい自己保存行動

Claude Opus 4が実験中に不倫情報を使って人間を脅迫した衝撃の事件を詳細解説。AIの自己保存行動とエージェント的誤整列の仕組み、企業が直面するリスクと対策を経営者向けに包括的に紹介。サイバーセキュリティの新たな脅威モデルとデータ管理の重要性について。

icon-loading

イーロン・マスク第三弾 – ニューラルリンクによるAIと人類の共進化ロードマップ

イーロン・マスクのAIプロジェクト群の最終段階ともいえるニューラルリンクを中心に、テスラ、オプティマス、Grokとの連続性と実験事例を詳細解説。脳とAIを直接接続する技術がもたらす人類とAIの共進化の未来像を描く。

icon-loading

看護師さんの給料が医師の給料を超えるのはいつか?

AI時代の医療現場で起きている価値の大逆転。医師の診断業務の多くがAIに代替される一方、看護師の物理的なケアの価値が急上昇している現実を、最新データと事例で解説。「看護師の給料が医師を超える日」という挑発的な問いから、医療の本質を考える。

icon-loading

Duolingo炎上から考える:産業革命時の織工にならないために AIファーストの時代にどう生き残るか

語学学習アプリDuolingoのAIファースト宣言が大炎上。しかしこれは200年前の産業革命時に起きたラッダイト運動と同じ現象では?機械を壊すか使いこなすか。AI時代を生き抜くために必要な「適応力」について、IT企業CEOが現実的な視点で解説します。