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

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

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

icon-loading

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

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

icon-loading

AIで脳が退化する?スポーツのように脳も鍛える必要がある理由

AIの普及により人間の脳機能が退化している現代、スポーツが貴族の遊びから必需品になったように、脳トレも必需品となる時代が到来。論理的思考力や記憶力を維持するための新しい習慣について、IT・AI開発会社GruneのCEOが実体験を交えて解説。人狼ゲームや将棋など具体的な脳トレ方法も紹介します。

icon-loading

止まったエスカレーターが教えてくれる、AIと脳の意外な共通点

AI技術と脳科学の意外な共通点を探る。人間の脳もコンピューターも「予測による差分処理」で驚異的なエネルギー効率を実現している。止まったエスカレーターで感じる違和感から自由エネルギー原理まで、最新の脳科学研究とAI開発の現場から見えてきた知能の本質とは?統合失調症や自閉症の新しい理解、動画圧縮技術との類似性など、技術と人間の境界を考察する。

icon-loading

「なんで?」に無限に答えるAIと育つ子どもたち

AIネイティブ世代の登場で教育が激変している。「虹はなんで見えるの?」という子どもの質問に親は3回で降参するが、AIは疲れることなく無限に答え続ける。シンガポールでは小学校でAI教育が始まり、40人の教室が時代遅れに。AIと協働することが基礎能力となる時代に企業はどう準備すべきか。

icon-loading

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

自家用車の稼働率はわずか5%—95%の時間は駐車場で眠っている現実をご存知ですか?サンフランシスコで300台が24時間稼働するWaymo無人タクシーの衝撃と、2025年東京実証実験開始のニュース。自動運転技術が描く未来都市では信号が消え、駐車場が公園に変わり、マイカーという概念が消滅する。IT・AI業界のCEOが語る、運転禁止時代の到来。