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も人間も学び方が変わらなくなってきた

テスラのオプティマスが動画学習で家事を習得し、ジョンズ・ホプキンス大学では手術ロボットが映像から医療技術を学ぶ時代に。従来の条件分岐プログラミングから「見て覚える」AI学習への革命的転換が、製造業・医療・サービス業に与える衝撃と、労働力不足解決への道筋を、AIコンサル企業CEOの視点で解説。

icon-loading

ローカルAIが変える未来: ChatGPTやClaudeを使っているだけでは時代に乗り遅れる

ローカルAI(エッジAI)がクラウドAIに代わる新たな選択肢として注目される理由を、AIコンサルタントが詳しく解説。AppleのLLM in a Flash、DeepSeekの効率革命、Microsoft Azure IoT Edge、NVIDIA Jetson、AWS Greengrassの最新動向から、自動運転・ヘルスケア・製造業での具体的活用事例まで、2025年のAI戦略に必要な知識を包括的に紹介。

icon-loading

原子爆弾からAIへ:アメリカが世界を制覇する投資戦略

日本企業のAI投資が米国の1%という衝撃的事実から、アメリカの歴史的投資姿勢、ウクライナ戦争で実証されたAI技術の重要性まで、企業存続に必要なAI投資の緊急性を解説。量子コンピューターを含む次世代技術への投資が企業の命運を分ける理由とは。

icon-loading

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

「AIはツールだから心配ない」と言う経営陣への警鐘。日本の労働人口49%が代替される現実、Grune AI Technologiesへの社名変更決断、プログラマーの生き残り戦略まで。産業革命とは根本的に違う今回のAI革命の本質を解説。

icon-loading

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

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

icon-loading

議事録AIと固有名詞の戦い:「やましたとしちか」問題

現在のGruneで運用している議事録AIの実装方法と、日本語特有の同音異義語問題への対処法を詳しく解説。LINE WorksのAI NoteとNotebookLMを活用した具体的な運用手順と、固有名詞リストを活用したプロンプト設計のコツを、実際の運用経験をもとに紹介。