0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SSHログインについて

Posted at

SSHログインとは

SSH(Secure Shell)は、暗号や認証の技術を利用して、リモートシステムへの安全なログインに使用されるプロトコルのこと。
SSHを使用してリモートシステムに接続して操作する際などによく使われる。
Macでは、ターミナルでSSHを利用できる。

基本的な構文

リモートシステム上のユーザー名とローカルシステムのユーザー名が同じ場合はユーザー名などを指定せずに以下だけで接続ができる。

ssh {接続しようとしているIPアドレスやドメイン名}

リモートシステムのユーザー名と異なる場合は2つの方法でログインする。

パスワード方式

ssh {リモートユーザー名} @ {接続しようとしているIPアドレスやドメイン名} -p {ポート番号}
Are you sure you want to continue connecting (yes/no)?

パスワードを求められるので入力してログイン。

秘密鍵方式

パスワード方式とは別に公開鍵(Public Key)と秘密鍵(Private Key)と呼ばれるセットの鍵を用いた認証を使ってログインすることもできる。

秘密鍵は公開したらダメな鍵。公開鍵は公開しても大丈夫。

公開鍵はリモートのサーバー側に置いておき、秘密鍵は自分のPCに保管する。

鍵の作り方

まず現在持っている鍵を確認する。

ls -al ~/.ssh

これでそれぞれの鍵の強度を確認できるらしい。
(鍵長が2048以上かつ暗号化方式がRSA、或いはECDSAやEd25519であればOKとのこと)

ssh-keygen -l -f ~/.ssh/id_rsa.pub

新しく鍵つくる。

ssh-keygen -t ed25519 -C "your_email@example.com"
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

ここで保存場所を指定してなければ~/.ssh/の中に鍵たちが入る。

Enter passphrase (empty for no passphrase): [Type a passphrase]

passphraseの入力を求められるが、これは秘密鍵にアクセスするためのもので、任意なので設定しないこともできる。

秘密鍵でログインする

下記でログインできる。

ssh -i {秘密鍵のファイルパス} {ユーザー名}@{サーバーのアドレス} -p {ポート番号}

※ポート番号は不要ならいらない

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?