OpenSSH 為 SSH 的開放原始碼版本,正確來說,是為了取代商業 SSH 而開發的開放性原始碼程式。 SSH Protocol 為一加密的通訊協定,特點為經過加密處理來避免傳輸過程中資料遭竊取。
安裝

Server 端

$ sudo aptitude install openssh-server

Client 端

$ sudo aptitude install openssh-client

設定

基本設定檔為 /etc/ssh/sshd_config (此為 server 版,client 為 ssh_config),設定檔內大部份選項都有註解說明用途,以下列出常用選項。

/etc/ssh/sshd_config

# SSH 監聽的通訊埠,建議更換掉,預設為 22。
Port 2235

# 是否允許 root 遠端登入,基於安全性考量建議關閉此功能,預設為 yes。
PermitRootLogin yes

# 此選項用以指定哪些使用者才可使用 SSH。
AllowUsers username

免密碼登錄

依照上面步驟安裝設定完成後,ssh 已可登入使用。但每次登入均需打一長串的密碼,實在不方便,且安全性上也較差。
dsa key

在本機執行以下指令產生dsa key:
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jouston/.ssh/id_rsa): [RETURN]
Enter passphrase (empty for no passphrase): [RETURN]
Enter same passphrase again: [RETURN]
Your identification has been saved in /home/jouston/.ssh/id_rsa.
Your public key has been saved in /home/jouston/.ssh/id_rsa.pub.
The key fingerprint is: aa:aa:aa:……:aa jouston@jouston.no-ip.com

基本上只需要連續按幾次[RETURN](就是鍵盤的[ENTER]鍵)

好了, 我們做到這一步已經弄到key了. 接下來需要把dsa.pub複製到遠端的伺服器:

# scp ~/.ssh/dsa.pub 10.1.1.1:.ssh/authorized_keys

搞定收工.

另外, 如果有多台機器要這樣免密碼登入的話, 你可以把後來的key在遠端機器那裡這麼作:

# cat dsa.pub » authorized_keys

直接附加上去就可以了
arrow
arrow
    全站熱搜

    neio 發表在 痞客邦 留言(0) 人氣()