紀錄一下如何利用 SSH & SCP without password

Step 1 — 設定 config 檔

[local-host]$ cd ~/.ssh
[local-host]$ vim config # 建立config檔

# config檔的格式如下
# 以下的內容都需搭配遠端的Server設定
Host            myHost              # 代號(自己決定)  
Hostname        192.168.11.12       # IP or Domain name  
Port            1022                # 指定埠口  
User            Taiker              # 使用者名稱  
identityfile    ~/.ssh/id_rsa_12    # 指定金鑰  

Step 2 — 產生 ssh-key

[local-host]$ cd ~/.ssh
# Generating public/private rsa key pair.
[local-host]$ ssh-keygen

# 產生完之後會有兩key(public/private)
[local-host]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts

Step 3 — Install public key on the remote-host.

[remote-host]$ vim ~/.ssh/authorized_keys 
# copy the local-host:~/.ssh/id_rsa.pub to remote-host:~/.ssh/authorized_keys

Step 4 — permission

[remote-host]$ chmod 755 ~/.ssh
[remote-host]$ chmod 644 ~/.ssh/authorized_keys

Step 5 — Finish config & login

# 先填好config的資訊
identityfile    ~/.ssh/id_rsa_12    # 指定金鑰(private)
[local-host]$ ssh myHost