Ubuntu和CentOS配置SSH无密码登录

一、安装ssh

ubuntu中使用命令:

$sudo apt-get install openssh-server openssh-client

centos中使用命令:

$sudo yum install openssh-server openssh-client

启动ssh使用命令:

$sudo service sshd start

二、配置无密码登录SSH

ubuntu中配置如下:

$ ssh-keygen -t dsa -P ''
Generating public/private dsa key pair.
Enter file in which to save the key (/home/aaron/.ssh/id_dsa):
Created directory '/home/aaron/.ssh'.
Your identification has been saved in /home/aaron/.ssh/id_dsa.
Your public key has been saved in /home/aaron/.ssh/id_dsa.pub.
The key fingerprint is:
bd:2c:ed:ab:6d:a9:b2:45:88:32:08:5a:d2:d9:ad:cc aaron@ubuntu
The key's randomart image is:
+--[ DSA 1024]----+
|                 |
| . o .           |
|o + . .          |
|o+ o o . .       |
|o o E . S .      |
|   o   . o .     |
|        o +.     |
|      .. +o      |
|      .oo++.     |
+-----------------+
(注:回车后会在~/.ssh/下生成两个文件:id_rsa和id_rsa.pub。这两个文件是成对出现的。)

将id_dsa.pub里面的内容加到用于认证的公钥文件中,命令如下:

$ cat id_dsa.pub >> authorized_keys
可以将这个生成的authorized_keys拷贝到别的机器上面
$ cat  ~/.ssh/authorized_keys | \
ssh aarron@192.168.1.108 "cat - >> ~/.ssh/authorized_keys"
登录localhost。在终端输入命令:ssh localhost(注:当ssh远程登录到其它机器后,你控制的是远程的机器,需要执行退出命令才能重新控制本地主机。)执行退出命令。输入命令:exit

如果配置过程中出现问题,一般的问题都是文件权限设置的不对,请把.ssh和authorized_keys的访问权限分别设置为755个600,命令如下:

$ chmod 755 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
上面是以Ubuntu平台为例子,下面来说说怎么在CentOS平台上面配置。

首先,需要设置一下/etc/ssh/sshd_config文件,请将/etc/ssh/sshd_config文件中下面三行的注释去掉:

$sudo vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
其余的步骤和在ubuntu下配置是一样的。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值