UBUNTU 安裝SSH
基本安裝
- 更新安裝源
sudo apt-get update
- 安裝
sudo apt-get install openssh-server
- 檢查
ps aux | grep ssh
Screenshot from 2017-01-02 15:49:46.png
如圖所示,有sshd表示ssh服務(wù)已經(jīng)啟動
使用
- 啟動
service ssh start
- 生成私鑰和公鑰
ssh-keygin -t rsa
默認(rèn)生成的密鑰在目錄~/.ssh/
配置
- 使root賬號可通過ssh登錄
sudo vim /etc/ssh/sshd_configs
- 在
PermitRootLogin without-password之前加#號,將其注釋掉- 在其后增加語句
PermitRootLogin yes
- 免密登錄
將本機(jī)(記為A)密鑰目錄(默認(rèn)為
~/.ssh/)下的id_rsa.pub,通過scp傳輸(或復(fù)制)到想免密登錄的其它機(jī)器(記為B)上。
scp ~/.ssh/id_rsa.pub xxx@hostname:~/.ssh/id_rsa.pub.a其中
~/.ssh/id_rsa.pub為A機(jī)器上的公鑰,xxx為登錄B機(jī)的用戶名 ,hostname為B機(jī)的主機(jī)名或IP地址,~/.ssh/id_rsa.pub.a為放入B機(jī)的路徑及文件名稱。
注意: 在執(zhí)行以上命令前B機(jī)應(yīng)該已經(jīng)裝有ssh服務(wù)
將B機(jī)器收到的“A機(jī)器的公鑰”加入B機(jī)器的authorized_keys文件中,該文件默認(rèn)同樣放置在
~/.ssh/目錄中。
cat ~/.ssh/id_rsa.pub.a >> ~/.ssh/authorized_keys至此,我們即可通過如下命令,在A機(jī)器上使用ssh免密登錄B機(jī)器
ssh xxx@hostnamessh hostname
