您的位置:首页 > 运维架构 > Linux

Linux SSH 免密码登录

2016-08-10 00:00 267 查看
摘要: Linux SSH 免密码登录 centos6.5

Linux SSH 免密码登录:

以下为centos6.5系统操作:

1、安装ssh,如果已经安装服务,则跳过

查看是否安装:

$ rpm -qa | grep ssh

# yum install openssh-server

(Ubuntu 安装命令 sudo apt-get install ssh)

启动ssh服务:

命令:service sshd restart 重启SSH服务;

命令:service sshd start 启动服务

命令:service sshd stop 停止服务

命令:netstat -antp | grep sshd 查看是否启动22端口。

命令:chkconfig sshd on 设置SSH服务为开机启动

命令:chkconfig sshd off 禁止 SSH服务为开机启动

# service sshd restart

2、修改服务器配置

修改sshd配置文件/etc/ssh/sshd_config

找到以下内容,并去掉注释符”#“
=========================
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
=========================

3、设置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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux SSH 免密码登录