Linux SSH 免密碼登陸:centos
如下爲centos6.5系統操做:服務器
一、安裝ssh,若是已經安裝服務,則跳過ssh
查看是否安裝:spa
$ rpm -qa | grep sshrest
# yum install openssh-serverserver
(Ubuntu 安裝命令 sudo apt-get install ssh)ip
啓動ssh服務:get
命令:service sshd restart 重啓SSH服務;it
命令:service sshd start 啓動服務 io
命令:service sshd stop 中止服務
命令:netstat -antp | grep sshd 查看是否啓動22端口。
命令:chkconfig sshd on 設置SSH服務爲開機啓動
命令:chkconfig sshd off 禁止 SSH服務爲開機啓動
# service sshd restart
二、修改服務器配置
修改sshd配置文件/etc/ssh/sshd_config
找到如下內容,並去掉註釋符」#「
=========================
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
=========================
三、設置ssh 登陸是否免密碼
檢查是否須要密碼:
$ ssh localhost
生成公鑰和私鑰:
$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
若是是遠程登陸,則須要將公鑰拷貝到另一臺機器上:
$ cat ~/.ssh/id_rsa.pub | ssh username@192.168.1.132 'cat ->> ~/.ssh/authorized_keys'
驗證ssh是否須要密碼:
$ ssh localhost
注意:
1) .ssh目錄的權限必須是700
2) .ssh/authorized_keys文件權限必須是600
受權:$ chmod 700 ~/.ssh/
$ chmod 600 ~/.ssh/authorized_keys
重啓sshd: $ /etc/init.d/sshd restart
若是是遠程,可將ip添加爲信任ip
vi /etc/hosts