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

LLMの秘密:「次の言葉を予測するだけ」で人間のように振る舞う技術

LLMは「次の言葉を予測するだけ」の仕組み?ChatGPTやClaudeの動作原理を分かりやすく解説。人間の会話との意外な共通点や、トランスフォーマー技術の基本から「考えるとは何か」という哲学的な問いまで、AI技術の本質を深掘りします。非エンジニア向けに専門用語を使わず、身近な例で説明。

icon-loading

24時間365日のAIテレアポに漂うディストピア感

24時間365日稼働するAIテレアポサービスの登場で浮き彫りになった技術の光と影。社会リソースの無駄遣いからAI vs AIの不毛な戦争まで、IT企業CEOが語るAI技術の適切な使い方と未来への警鐘。

icon-loading

SEO対策は無駄に?GAIO/LLMOの対策が必要?ただ最後はどうなるのか

Google AI Overviewによる検索の根本的変化を分析。CTR最大56%減少の実データと、GAIO/LLMO等の新戦略を解説。しかし「AIに選ばれる」ことに本当に意味があるのか?従来のWebマーケティングモデルの限界と今後の展望をAI企業CEOが考察。

icon-loading

AIフレンドリージャパニーズとシンプリファイドイングリッシュ

AI音声入力と議事録自動化の実践から見えた、日本語特有の同音異義語問題とその対策について解説。シンプリファイドイングリッシュを参考にした「AIフレンドリージャパニーズ」の考え方で、機械にも人間にも理解しやすいコミュニケーション手法を提案。AI時代の新しい働き方のヒントが満載。

icon-loading

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

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

icon-loading

AI実装における少子高齢化の絶好機

少子高齢化は本当に日本の弱点なのか?インドネシア出張で目撃した「人材過多の罠」から見えてきた、AI時代における日本の隠れた競争優位性。労働力不足がなぜAI実装を加速させるのか、具体的なデータと現地体験をもとにGruneのCEOが解説します。