Linux下配置ssh无密码登陆

mkdir ~/.ssh

chmod 700 ~/.ssh

ssh-keygen -t rsa

ssh-keygen -t dsa

然后,在节点 dbtest1 执行以下命令

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

ssh dbtest2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

ssh dbtest2 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

scp ~/.ssh/authorized_keys dbtest2:~/.ssh/authorized_keys

节点1:

node1:~ #cd /root

node1:~ # mkdir .ssh

node1:~ # chmod 700 .ssh

node1:~ # ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

b0:1d:73:0a:99:2a:ee:ce:cd:5f:de:e5:db:c9:ab:6e [MD5] [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|                 |

|       o         |

|      = o .      |

|     . = =       |

|  . . . S        |

| . .             |

|  .     .   .    |

| o o   o . oEo . |

| .+ o.. . .o=o=. |

+--[MD5]----------+

node1:~ # ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

9c:93:19:6b:df:bd:f3:01:b6:82:be:32:0c:ee:b0:68 [MD5] [email protected]

The key‘s randomart image is:

+--[ DSA 1024]----+

|                 |

|                 |

|        .        |

|       . *       |

|        S    o   |

|     . . o....o  |

|   .. o  ....... |

| E. o. +.   . ...|

|.. ...  oo.   .o.|

+--[MD5]----------+

node1:~ #

节点2

node2:~ # cd /root

node2:~ # mkdir .ssh

node2:~ # chmod 700 .ssh/

node2:~ # ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

f2:ca:0c:73:98:04:55:69:48:1a:9a:a8:8e:0c:96:0c [MD5] [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|  ..oo..         |

|.o +. o          |

|E o  .           |

|+ ..             |

|o+  . . S        |

|*  . o o         |

|.o  = . .        |

|     * .         |

|      +          |

+--[MD5]----------+

node2:~ # ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

6a:c4:e1:cc:bb:c7:32:51:5c:96:49:46:24:df:86:ad [MD5] [email protected]

The key‘s randomart image is:

+--[ DSA 1024]----+

|        .+=o     |

|         +=+     |

|      .. oo +    |

|     = .o  o     |

|      *.S E      |

|     ..o         |

|      +o         |

|     .o.o        |

|      .+         |

+--[MD5]----------+

node2:~ #

同步authorized_key

node1:~/.ssh # cat id_rsa.pub >>authorized_keys

node1:~/.ssh # cat id_dsa.pub >>authorized_keys

node1:~/.ssh # ssh node2 cat /root/.ssh/id_rsa.pub >> authorized_keys

The authenticity of host ‘node2 (10.0.0.31)‘ can‘t be established.

ECDSA key fingerprint is b4:30:1b:97:e9:75:1e:e2:2c:85:91:2a:76:85:77:ce [MD5].

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘node2,10.0.0.31‘ (ECDSA) to the list of known hosts.

Password:

node1:~/.ssh # ssh node2 cat /root/.ssh/id_dsa.pub >> authorized_keys

Password:

node1:~/.ssh # scp authorized_keys node2:/root/.ssh/

Password:

authorized_keys                               100% 1984     1.9KB/s   00:00

node1:~/.ssh #

测试

node1:~/.ssh # ssh node2 date

Sat May  9 05:40:58 CST 2015

node1:~/.ssh #

node2:~ # ssh node1 date

Sat May  9 05:41:03 CST 2015

node2:~ #

时间: 2024-11-03 01:07:14

Linux下配置ssh无密码登陆的相关文章

linux下建立ssh无密码登陆

1.在机器1中生成密钥 ssh-keygen -t rsa 2.在机器2中创建文件 vi authorized_keys 3.将生成的公钥id_rsa.pub拷贝到机器2中 /root/.ssh 4.加入授权 cat id_rsa.pub >>authorized_keys 5.修改authorized_keys文件的权限 chmod 400 authorized_keys

配置 ssh无密码登陆

首先确保 linux系统中已经安装了ssh,否则先安装 ssh,ubuntu 系统可以执行 sudo apt-get install ssh 接下来开始配置 ssh无密码登陆 确保在 /home/user用户目录下存在.ssh目录,可以使用一下命令进行查看 ls -a /home/user 如果不存在可以自己手动创建一个 mkdir /home/user/.ssh 接下来没输入命令: ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 解释一下: ssh-keyge

Linux(Centos)配置OpenSSH无密码登陆

最近在搭建Hadoop环境需要设置无密码登陆,所谓无密码登陆其实是指通过证书认证的方式登陆,使用一种被称为"公私钥"认证的方式来进行ssh登录. 在linux系统中,ssh是远程登录的默认工具,因为该工具的协议使用了RSA/DSA的加密算法.该工具做linux系统的远程管理是非常安全的.telnet,因为其不安全性,在linux系统中被搁置使用了. " 公私钥"认证方式简单的解释:首先在客户端上创建一对公私钥 (公钥文件:~/.ssh/id_rsa.pub: 私钥文

配置ssh无密码登陆

好几次都双机互配后才wanshi ,总记不住方向,记到这儿 A要链接B,A把自己的公钥给B 1 [email protected]:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/zxw/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase aga

配置ssh无密码登陆Linux

Windows下面的话需要安装git,或者其他能执行shell命令的软件 1.首先要先修改SSH的配置文件 vi /etc/ssh/sshd_config#修改配置文件 #如果被#注释了,就取消#号,改为如下配置: RSAAuthentication设置为yes,#意思是设置开启使用RSA算法的基于rhosts的安全验证: PubkeyAuthentication设置为yes #意思是设置开启公钥验证: AuthorizedKeyFiles #后面的目录,是你上传的公钥所保存的文件: Stric

配置SSH无密码登陆(为Hadoop分布式部署准备)

SSH 无密 码原理简介 :首先在 hadoop1 上生成一个密 钥对,包括一个公钥和一个私钥,并将公钥复制到所有的 slave(hadoop2-hadoop4) 上.然后当 master 通 过 SSH 连接 slave 时, slave 就会生成一个随机数并用 master 的公 钥对随机数进行加密,并发送给 master .最后 master 收到加密数之后再用私 钥解密,并将解密数回传给 slave , slave 确 认解密数无误之后就允许 master 不 输入密码进行连接了 2 ,

linux下设置SSH无密码登录

ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所有主机的防火墙处于关闭状态. 在主机A上执行如下: 1. $cd ~/.ssh 2. $ssh-keygen -t rsa  --------------------然后一直按回车键,就会按照默认的选项将生成的密钥保存在.ssh/id_rsa文件中. 3. $cp id_rsa.pub authorized_keys 这步完成后,正常情况下就可以无密码登录本机了,即ssh lo

ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访问

ssh到192.168.88.61机器上,需要密码,这样对一些脚本工作不方便,因为需要密码,也就是需要人工干预.最近发现一个命令ssh-copy-id很方便,测试了一下,果然好用,记录下来: 在192.168.88.61机器上 1)运行:ssh-keygen -t rsa 2)然后拍两下回车(均选择默认) 3)运行: ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] 4)再输入192.168.88.62机器上的root密码 此时,再ss

linux下实现ssh无密码登录访问

在192.168.9.51机器上 1)运行:#ssh-keygen -t rsa 2)然后拍两下回车(均选择默认) 3)运行: #ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] 4)再输入17机器上的root密码 此时,再ssh 到17机器,则不需要密码了.相互之间scp,也不需要密码 5) 图方便的话 可以加入别名 #alias 79.17='ssh [email protected]'  以后直接输入#79.17  就ok了