Linux SSH 免密码登陆

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

相关文章
相关标签/搜索