• Japanese

MENU

共通認証システム 日吉キャンパス 慶應義塾公式ウェブサイト 慶應義塾大学日吉メディアセンター 慶應義塾の電力使用状況

Mac OS X から Unix へのリモートログイン方法

Mac OS X から Unix へのリモートログイン方法

ここでは Mac OS X 10.6 Snow Leopard から,SSH の公開鍵認証を利用して,Unix へリモートログインする方法を紹介します.

公開鍵と秘密鍵の生成方法

  • Mac OS X にて“ターミナル”を起動します. (以下,ターミナルでの操作となります)

  • ssh-keygen コマンドを実行します.

    hostname:~ username$ ssh-keygen -t rsa
    
  • 鍵の作成場所とフィル名を確認されますので,問題がなければそのまま [Enter] キーを押します.

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/username/.ssh/id_rsa):
    Created directory '/Users/username/.ssh'.
    
  • パスフレーズの入力を求められますので,パスワードとは違う,比較的長い文字列を指定してください.

    Enter passphrase (empty for no passphrase):
    

    確認のため再度入力を求められますので,同じ文字列を指定します.

    Enter same passphrase again:
    
  • 作成された鍵に関する情報が出力されます.

    Your identification has been saved in /Users/username/.ssh/id_rsa.
    Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
    The key fingerprint is:
    xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx username@hostname
    The key's randomart image is:
    +--[ RSA 2048]----+
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    |                 |
    +-----------------+
    

    この例では /Users/username/.ssh/id_rsa が秘密鍵,/Users/username/.ssh/id_rsa.pub が公開鍵となります.

公開鍵の転送

作成した公開鍵を upload.user.keio.ac.jpsftp を利用して転送します.

接続方法

  • 下記のコマンドを実行し,upload.user.keio.ac.jp に接続します.

    hostname:~ username$ sftp ua000000@upload.user.keio.ac.jp
    Connecting to upload.user.keio.ac.jp...
    

    “ua000000”はあなたのユーザー名に置き換えて入力します. (以下全て)

  • はじめて upload.user.keio.ac.jp に接続した場合,サーバーの公開鍵に関する情報が表示され,受け入れるか確認を求められます.

    The authenticity of host 'upload.user.keio.ac.jp (2001:200:167:2018::160)' can't be established.
    RSA key fingerprint is c4:02:5d:ba:21:b8:20:a3:5e:af:41:23:86:2b:91:e5.
    Are you sure you want to continue connecting (yes/no)? yes
    
  • 問題がなければ受け入れるため,yes と入力します.

    Warning: Permanently added 'upload.user.keio.ac.jp,2001:200:167:2018::160' (RSA) to the list of known hosts.
    

    受け入れると ~/.ssh/known_hosts にリストされます.

  • ua000000@upload.user.keio.ac.jp's password:
    

    パスワードの入力を求められますので,パスワードを入力します.

公開鍵を初めて用意する場合

  • 下記の様にコマンドを実行します.

    sftp> mkdir .ssh
    sftp> chmod 700 .ssh
    Changing mode on /nfs/nfs00/md000/ua000000/.ssh
    sftp> put .ssh/id_rsa.pub .ssh/authorized_keys
    sftp> chmod 600 .ssh/authorized_keys
    sftp> quit
    

既にある公開鍵に追加する場合

  • 下記の様にコマンドを実行し,既存の authorized_keys を手元に転送します.

    stfp> lmkdir tmp
    sftp> lcd tmp
    sftp> get .ssh/authorized_keys
    Fetching /nfs/nfs00/md000/ua000000/.ssh/authorized_keys to authorized_keys
    /nfs/nfs00/md000/ua000000/.ssh/authorized_key 100%  ???     ?.?KB/s   00:00
    sftp> quit
    
  • 転送してきた authorized_keys に公開鍵を追加し,再度 sftpupload.user.keio.ac.jp に転送します.

    hostname:~ username$ cat ~/.ssh/id_rsa.pub >> ~/tmp/authorized_keys
    hostname:~ username$ sftp ua000000@upload.user.keio.ac.jp
    Connecting to upload.user.keio.ac.jp...
    ua000000@upload.user.keio.ac.jp's password:
    sftp> put tmp/authorized_keys .ssh/authorized_keys
    sftp> chmod 600 .ssh/authorized_keys
    sftp> quit
    

接続方法

  • ssh コマンドを実行し,login20.user.keio.ac.jp 等に接続します.

    hostname:~ username$ ssh ua000000@login20.user.keio.ac.jp
    
  • するとダイアログが表示され,“Enter your password for the SSH key "id_rsa".”とパスフレーズの入力を求められます.
    ここでパスフレーズを入力し“OK”ボタンをクリックすると接続されます.
    (「パスワード」と表示されますが「パスフレーズ」を入力します)

秘密鍵のパスフレーズ変更方法

  • ssh-keygen コマンドを実行します.

    hostname:~ username$ ssh-keygen -p
    
  • 鍵ファイルの場所を確認されますので,問題がなければそのまま [Enter] キーを押します.

    Enter file in which the key is (/Users/username/.ssh/id_rsa):
    
  • 現在利用しているパスフレーズを入力します.

    Enter old passphrase:
    Key has comment '/Users/username/.ssh/id_rsa'
    
  • 新しいパスフレーズを入力します.

    Enter new passphrase (empty for no passphrase):
    

    再度パスフレーズを入力します.

    Enter same passphrase again:
    Your identification has been saved with the new passphrase.
    

これで秘密鍵に設定されているパスフレーズは変更されました. この秘密鍵を利用して login20.user.keio.ac.jp 等へログインする場合には,変更された新しいパスフレーズを入力する必要があります.

最終更新日: 2011年10月28日

内容はここまでです。