cat /proc/version
Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Nov 19 22:10:57 UTC 2015

Linux version 2.6.32-642.6.2.el6.x86_64 (mockbuild@worker1.bsys.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ) #1 SMP Wed Oct 26 06:52:09 UTC 2016

authorized_keys  是执行ssh host1后程序在目的地host创建的文件,而出发地的kownhosts的文件会被追加。

【学习路径】
1-看执行过程中的窗口输出语句;
2-比较执行前后的出发地、目的地的文件新增情况、文件内容的新增情况;
[root@bigdata-server-01 ~]# cat /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $ # This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value. # If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#ListenAddress 0.0.0.0
#ListenAddress :: # The default requires explicit activation of protocol 1
#Protocol 2 # HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key # Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024 # Ciphers and keying
#RekeyLimit default none # Logging
# obsoletes QuietMode and FascistLogging
#LogLevel INFO # Authentication: #LoginGraceTime 2m
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10 #RSAAuthentication yes
#PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here!
#PermitEmptyPasswords no # Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no # Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes # GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no # Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# and ChallengeResponseAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.
UsePAM yes #AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
UsePrivilegeSeparation sandbox # Default for new installations.
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none # no default banner path
#Banner none # Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS # override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server # Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
UseDNS no
AddressFamily inet
PermitRootLogin yes
SyslogFacility AUTHPRIV
PasswordAuthentication yes
[root@bigdata-server-01 ~]#

  

 
    [m]
$ssh-keygen -t rsa
$cd ~/.ssh
$cp id_rsa.pub authorized_keys_hadoop1
[s]
$ssh-keygen -t rsa
$cd ~/.ssh
$cp id_rsa.pub authorized_keys_hadoop2
$scp authorized_keys_hadoop2 root@hadoop1:~/.ssh [m]
cat authorized_keys_hadoop1 authorized_keys_hadoop2 >> authorized_keys
chmod authorized_keys
scp authorized_keys root@hadoop2:~/.ssh
[m s]
$chmod authorized_keys [check]
ssh hadoop1
ssh hadoop2

[hadoop@bigdata-server- ~]$ ssh-keygen -t rsa  -b ;
Generating public/private rsa key pair.
Enter file in which to save the key (/usr/hadoop/.ssh/id_rsa):
Created directory '/usr/hadoop/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /usr/hadoop/.ssh/id_rsa.
Your public key has been saved in /usr/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:FOplMhXfwr9kCXqymSA0jKO1honV9K+lSh4PIuaoEwQ hadoop@bigdata-server-
The key's randomart image is:
+---[RSA ]----+
| . +. |
|E = . o + . |
|. = = = + = . |
|.B + o B . + . |
|* o . o S . = |
|.. . = * o . |
|.o. + o + . |
|=. + = |
|+o o . |
+----[SHA256]-----+
[hadoop@bigdata-server- ~]$ ssh-copy-id localhost;
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/usr/hadoop/.ssh/id_rsa.pub"
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:+xC9Wc2SSvYj9LLM2PjPrUw9PhRoa7zoLzXeE0AqG7g.
ECDSA key fingerprint is MD5:cd:::e7:f1:ee::1f:ba:cb::d9:c7::1f:f8.
Are you sure you want to continue connecting (yes/no)?
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:+xC9Wc2SSvYj9LLM2PjPrUw9PhRoa7zoLzXeE0AqG7g.
ECDSA key fingerprint is MD5:cd:::e7:f1:ee::1f:ba:cb::d9:c7::1f:f8.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@localhost's password: Number of key(s) added: Now try logging into the machine, with: "ssh 'localhost'"
and check to make sure that only the key(s) you wanted were added. [hadoop@bigdata-server- ~]$ ssh localhost
Last login: Thu Nov :: from 127.0.0.1 Welcome to Alibaba Cloud Elastic Compute Service ! [hadoop@bigdata-server- ~]$ ssh-copy-id bigdata-server-;
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/usr/hadoop/.ssh/id_rsa.pub"
The authenticity of host 'bigdata-server-02 (120.78.187.241)' can't be established.
ECDSA key fingerprint is SHA256:hsqZ6Utb+5QRXxE98U5E88MoOBwCj+oTbPjkgyO5WQo.
ECDSA key fingerprint is MD5::bb:cb:::fe:8c:dd::e0:a6:::e6:5e:e4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@bigdata-server-'s password: Number of key(s) added: Now try logging into the machine, with: "ssh 'bigdata-server-02'"
and check to make sure that only the key(s) you wanted were added. [hadoop@bigdata-server- ~]$ ssh bigdata-server-
Last login: Thu Nov :: from 120.78.187.72 Welcome to Alibaba Cloud Elastic Compute Service ! [hadoop@bigdata-server- ~]$ exit
logout
Connection to bigdata-server- closed.
[hadoop@bigdata-server- ~]$ ssh-copy-id bigdata-server-;
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/usr/hadoop/.ssh/id_rsa.pub"
The authenticity of host 'bigdata-server-03 (120.78.188.28)' can't be established.
ECDSA key fingerprint is SHA256:i2u/BSXoUqwlTXtsWpDdWzZMZtjRRY2LCvBLXHFAzHQ.
ECDSA key fingerprint is MD5::2e::d7::::1e::dc:a6:b3::1d:6a:7a.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
hadoop@bigdata-server-'s password: Number of key(s) added: Now try logging into the machine, with: "ssh 'bigdata-server-03'"
and check to make sure that only the key(s) you wanted were added. [hadoop@bigdata-server- ~]$ ssh bigdata-server-
Last login: Thu Nov :: from 120.78.187.72 Welcome to Alibaba Cloud Elastic Compute Service ! [hadoop@bigdata-server- ~]$
[root@bigdata-server- .ssh]# rm -rf /usr/hadoop/.ssh;
[root@bigdata-server- .ssh]# ll -as /usr/hadoop/.ssh;
ls: cannot access /usr/hadoop/.ssh: No such file or directory
[root@bigdata-server- .ssh]# ll -as /usr/hadoop/.ssh;
total
drwx------ hadoop hadoop Nov : .
drwxr-xr-x hadoop hadoop Nov : ..
-rw------- hadoop hadoop Nov : id_rsa
-rw-r--r-- hadoop hadoop Nov : id_rsa.pub
[root@bigdata-server- .ssh]# ll -as /usr/hadoop/.ssh;
total
drwx------ hadoop hadoop Nov : .
drwxr-xr-x hadoop hadoop Nov : ..
-rw------- hadoop hadoop Nov : authorized_keys
-rw------- hadoop hadoop Nov : id_rsa
-rw-r--r-- hadoop hadoop Nov : id_rsa.pub
-rw-r--r-- hadoop hadoop Nov : known_hosts
[root@bigdata-server- .ssh]# cat /usr/hadoop/.ssh/known_hosts;
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKVJATfy765ZoMvOxe7/wIA2Y5OCLMoFVaFRPUHoLmZbLO+Drj9rj8yqKenWv5wylrJKZnSVOQvS3tb7Cb2IqIY=
bigdata-server-,120.78.187.241 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLAP1ETeJ+6aYu6KyIzlREQJVBmyHGinZR+FLKONCUIYxzJ1HmNo0mSgWskRjwNbXySKbYianmSIbwwamHeH+=
[root@bigdata-server- .ssh]# cat /usr/hadoop/.ssh/known_hosts;
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKVJATfy765ZoMvOxe7/wIA2Y5OCLMoFVaFRPUHoLmZbLO+Drj9rj8yqKenWv5wylrJKZnSVOQvS3tb7Cb2IqIY=
bigdata-server-,120.78.187.241 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLAP1ETeJ+6aYu6KyIzlREQJVBmyHGinZR+FLKONCUIYxzJ1HmNo0mSgWskRjwNbXySKbYianmSIbwwamHeH+=
bigdata-server-,120.78.188.28 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBVJUFAiA4PH0oLZEqySzvqYENGl2lGhQdZqRI5EFUOMZz0pbBxEcvInTBL/DS76gh/48xJzX+t4ngFzd6sKNDg=
[root@bigdata-server- .ssh]#
[root@bigdata-server-02 ~]# rm -f /usr/hadoop/.ssh/*;
[root@bigdata-server-02 ~]# ll -as /usr/hadoop/.ssh;
total 8
4 drwx------ 2 hadoop hadoop 4096 Nov 23 23:40 .
4 drwxr-xr-x 15 hadoop hadoop 4096 Nov 23 22:13 ..
[root@bigdata-server-02 ~]# ll -as /usr/hadoop/.ssh;
total 12
4 drwx------ 2 hadoop hadoop 4096 Nov 23 23:48 .
4 drwxr-xr-x 15 hadoop hadoop 4096 Nov 23 22:13 ..
4 -rw------- 1 hadoop hadoop 406 Nov 23 23:48 authorized_keys
[root@bigdata-server-02 ~]#

  

【试验】

host0无密登录host1,是由于之前已经正确输入host1的密码了,结果写入了自己的known_hosts和1、2的authorized_keys;

那么,推测当host2的密码修改后,原host0进入host1的无密登录失效,即known_hosts、authorized_keys的文本内容是密码的函数。

vim /etc/hosts

ipa a

ipb b

scp

4节点a b c d 免密登录快捷配置

各个节点分别执行下2行命令;

ssh-keygen -t rsa -b 2048; ssh-copy-id localhost;

ssh-copy-id a;ssh-copy-id b;ssh-copy-id c;ssh-copy-id d;

输入yes 和各个节点的密码;

#!/bin/bash
hostset=('hadoop-name' 'hadoop-data-a' 'hadoop-data-b')
for i in ${hostset[@]}; do
cmd=`ssh $i "mkdir -p ~/test/hadoop/;ls;"`;
echo $i $cmd;
done

  

配置hadoop用户SSH无密码登陆 的2种方式 落脚点是 可以ssh免密进入的主机名写入动作发出主机的 known_hosts,而被无密进入主机的authorized_keys文件 免密登录的更多相关文章

  1. 烂泥:学习ssh之ssh无密码登陆

    本文由秀依林枫提供友情赞助,首发于烂泥行天下 最近一个月没有写过文章,主要是刚刚换的新工作.新公司服务器OS使用的是ubuntu server版,和以前熟悉的centos还是有很多不同的. 刚好这几天 ...

  2. ssh无密码登陆远程机,pssh轻批量工具

    #B(client)--------A(g_server)#A:   ssh-keygen -t rsa (g_server)#B:    scp -P 58422 root@g_server_ip: ...

  3. linux ssh 无密码登陆

    要点:有时候ssh localhost 无法登陆本机,但各种设置都正确.重启下就好了...... 参考地址:http://bbs.csdn.net/topics/370109654 三台机器实现互相之 ...

  4. 批量设置ssh无密码登陆脚本

    最近要给集群设置ssh无密码登陆,如果需要手动设置这个无密码登陆,所以在网上找了几个脚本,亲测下面这个好使,并且设置比较简单. 需要用root账户执行,我也是要给root账户设置无密码登陆. 首先我们 ...

  5. hadoop-13-root ssh无密码登陆

    hadoop-13-root ssh无密码登陆 生产机器禁止ROOT远程SSH登录: vi /etc/ssh/sshd_config 把 PermitRootLogin yes 改为 PermitRo ...

  6. 批量实现SSH无密码登陆认证脚本

    批量实现SSH无密码登陆认证脚本 问题背景 使用为了让linux之间使用ssh不需要密码,可以采用了数字签名RSA或者DSA来完成.主要使用ssh-key-gen实现. 1.通过 ssh-key-ge ...

  7. ssh免密钥登陆的两种方式

    ssh 免密钥登陆的两种方式第一种:直接使用命令复制过去ssh-copy-id root@192.168.3.113批量复制for i in {113..140}; do ssh-copy-id ro ...

  8. 安装SSH,配置SSH无密码登陆

    环境:ubuntu16.04 Ubuntu 默认已安装了 SSH client,所以我们还需要安装 SSH server: sudo apt-get install openssh-server 安装 ...

  9. Linux设置ssh无密码登陆

    最近在折腾Hadoop,要用到主机间无密码登陆,设置的时候遇到了一些问题,这里记录一下. 假设A需要无密码登陆B. 那么首先需要在A上使用ssh-keygen生成id_rsa.pub的公钥,生成时,一 ...

随机推荐

  1. json键的不能像值一样拼写的问题

    今天碰到了一个json的键不能拼写的问题 解决方法是  先把json对象作为一个字符串拼写  然后再通过eavl函数转为json对象 $(".select_date").each( ...

  2. 关于 ajax 动态返回数据 css 以及 js 失效问题(动态引入JS)

    ajax 毕竟是异步的 所以动态加载出来的数据 难免遇到 css 或者 js 失效的问题,所以要动态加载 css ji等文件了 1.公共方法 load //动态加载 js /css function ...

  3. 十六进制字符串jpg图片互转

    十六制字符串jpg图片互转(格式:FFD8FFE000104A******)如:FFD8FFE000104A46494600010100000100010000FFDB0043000806060706 ...

  4. html移动端 -- meta-模板 + rem

    第一种方式: ps 不用除以2<header> <meta charset="utf-8"> <meta name="viewport&qu ...

  5. babel ---- presets字段设定转码规则

    presets字段设定转码规则,官方提供以下的规则集,你可以根据需要安装. # ES2015转码规则 $ npm install --save-dev babel-preset-es2015 # re ...

  6. Codeforces 868F Yet Another Minimization Problem(分治+莫队优化DP)

    题目链接  Yet Another Minimization Problem 题意  给定一个序列,现在要把这个序列分成k个连续的连续子序列.求每个连续子序列价值和的最小值. 设$f[i][j]$为前 ...

  7. mac git安装及github配置

    准备下载一个react的demo程序包,需要本地用到git.早就向配置了,那就安装配置一下吧. 首先,原来mac已经安装了git,版本 2.7 ,我用 brew又安装了一份git 版本 2.10.2. ...

  8. update tableView contenSize

    NSIndexPath *messageIndexPath = [NSIndexPath indexPathForRow:afterRowCount-1 inSection:0];    [self. ...

  9. hql 时间

    1.hql中时间格式转换 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String d ...

  10. Adam:大规模分布式机器学习框架

    引子 转载请注明:http://blog.csdn.net/stdcoutzyx/article/details/46676515 又是好久没写博客,记得有一次看Ng大神的訪谈录,假设每周读三篇论文, ...