LoginSignup
10
12

More than 5 years have passed since last update.

OSXでssh-copy-idを使ってリモートサーバにパスワードなしでログインする

Last updated at Posted at 2014-07-19

OSXでssh-copy-idを使う方法です。

何ができる?

  1. sshでサーバにログインする際のパスワード入力が不要になる。
  2. そのために必要なssh公開鍵の配布を簡単に行うことができる。

インストール

beautifulcode/ssh-copy-id-for-OSX - GitHubを使います。

  1. ダウンロード

    curl https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/ssh-copy-id.sh -o /usr/local/bin/ssh-copy-id
    
  2. 実行権限を付与

    chmod +x /usr/local/bin/ssh-copy-id
    

使い方

  1. 公開鍵を生成します。~/.ssh/id_rsa.pubが存在する場合は不要です。

    ssh-keygen  
    

    以下が生成されます。

    ~/.ssh/id_rsa.pub
    
  2. 公開鍵を配布します。

    通常

    ssh-copy-id [ユーザID]@[リモートサーバ]
    ssh-copy-id root@192.168.100.10 #例
    

    ~/.ssh/id_rsa.pub以外の公開鍵を使う場合

    ssh-copy-id -i 公開鍵のフルパス [ユーザID]@[リモートサーバ]
    ssh-copy-id ~/.ssh/myidentity.pub root@192.168.100.10 #例
    

    ※ ログインパスワードを聞かれるので入力します。

  3. sshでリモートのサーバにログインします。

    ssh [ユーザID]@[リモートサーバのアドレス]
    ssh root@192.168.100.10 #例
    

    ※ ログインパスワードは聞かれません。

10
12
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
10
12