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同士が秘密の暗号で”性格”を受け渡す時代:Anthropicが明かした「サブリミナル学習」

Anthropicの2025年の研究で、AIが数字列だけで「フクロウ好き」という性格を別のAIに伝達した事実が判明した。人間には読めない暗号で好みや悪癖までが感染する「サブリミナル学習」の仕組みと、AI開発の前提を覆すリスク、現時点の対策を解説します。

icon-loading

ヤマハもホンダも消えた街。別世界の中国深圳

40年前の漁村が人口1,700万人の「アジアのシリコンバレー」に変貌した深圳。街を埋め尽くす電動スクーター、財布すら不要なキャッシュレス社会、そしてデータ統治という制度設計の本質。現地で目撃した中国のAI最前線のリアルをレポートします。

icon-loading

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

AIが事実と異なる情報をもっともらしく生成する「ハルシネーション」は、実は創造性と表裏一体の特性である。temperatureやtop_pによる制御方法、ポストイットの発明に見る人間の「失敗から生まれた創造」との類似性、経営判断での活用法を解説します。

icon-loading

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

画像認識ではすでに2015年にAIが人間を超えている。診断・画像読影など医師の仕事の多くがAIに代替される一方、身体接触を伴う看護師の仕事は代替が難しい。医療分野で起きつつある「経済価値の大逆転」の可能性と、AI時代の価値の再定義を考察します。

icon-loading

運転が禁止される日は来るのか?:自家用車の稼働率はわずか5% | 自動運転車が走る都市

自家用車は95%の時間、駐車場で眠っている。一方サンフランシスコでは300台のWaymo無人タクシーが24時間稼働中。自動運転技術の安全性の仕組み、すべての車が自動運転になった場合の思考実験、そして変化するビジネスモデルの全体像を考察します。

icon-loading

「AIはツールだから心配ない」と言う経営陣は頭の中がお花畑か嘘を言っている

日本の労働人口の49%がAIに代替されるという予測は現実味を帯びている。過去の産業革命と違い、今回は新しい職業の創出が追いつかない可能性が高い。社名変更の決断を下した取締役会議の裏側と、エントリーレベル職の消滅に備える生き残り戦略を解説します。