先看问题提示:
[root@data ~]# start-dfs.sh
Starting namenodes on [data]
root@data's password:
data: starting namenode, logging to
/opt/software/hadoop260/logs
/hadoop-root-namenode-data.out
root@localhost's password:
localhost: starting datanode, logging to
/opt/software/hadoop260/logs
/hadoop-root-datanode-data.out
Starting secondary namenodes [0.0.0.0]
root@0.0.0.0's password:
0.0.0.0: starting secondarynamenode, logging to
/opt/software/hadoop260/logs
/hadoop-root-secondarynamenode-data.out
首先确定免密是否做好,建议直接重做:
删除所有文件后输入ssh-keygen -t rsa
连续按三次enter
切换到.ssh目录下 cd /root/.ssh
ssh-copy-id -i id_rsa.pub root@主机名
ssh root@主机名
提示还是需要输入密码
root@data's password:
Last failed login: Sat Apr 10 09:52:11 CST 2021
from localhost on ssh:notty
There was 1 failed login attempt since
the last successful login.
Last login: Sat Apr 10 09:48:27 2021
from 192.168.133.1
[root@data ~]# exit
先看.ssh中文件的权限
[root@data .ssh]# ll
total 16
-rw-------. 1 root root 782 Apr 10 10:11 authorized_keys
-rw-------. 1 root root 1679 Apr 10 09:55 id_rsa
-rw-------. 1 root root 391 Apr 10 09:55 id_rsa.pub
-rw-------. 1 root root 522 Apr 10 09:14 known_hosts
文件权限不足,修改文件权限
[root@data .ssh]# chmod -R 644 id_rsa.pub
[root@data .ssh]# chmod -R 644 known_hosts
[root@data .ssh]# chmod -R 600 id_rsa
[root@data .ssh]# ll
total 16
-rw-r--r--. 1 root root 782 Apr 10 10:11 authorized_keys
-rw-------. 1 root root 1679 Apr 10 09:55 id_rsa
-rw-r--r--. 1 root root 391 Apr 10 09:55 id_rsa.pub
-rw-r--r--. 1 root root 522 Apr 10 09:14 known_hosts
再次尝试
[root@data .ssh]# ssh root@data
root@data's password:
Last login: Sat Apr 10 10:11:30 2021 from data
还是需要输入密码
查看/root的权限
[root@data ~]# cd ../
[root@data /]# ll
total 28
lrwxrwxrwx. 1 root root 7 Apr 8 00:35 bin -> usr/bin
dr-xr-xr-x. 5 777 root 4096 Apr 8 00:39 boot
drwxr-xr-x. 20 root root 3260 Apr 10 09:48 dev
drwxr-xr-x. 76 root root 8192 Apr 10 09:48 etc
drwxr-xr-x. 3 root root 24 Apr 8 00:38 home
lrwxrwxrwx. 1 root root 7 Apr 8 00:35 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Apr 8 00:35 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 media
drwxr-xr-x. 2 root root 6 Apr 11 2018 mnt
drwxr-xr-x. 5 root root 50 Apr 8 18:27 opt
dr-xr-xr-x. 142 root root 0 Apr 10 09:48 proc
dr-xr-x---. 5 777 root 4096 Apr 9 16:54 root
drwxr-xr-x. 24 root root 660 Apr 10 09:48 run
lrwxrwxrwx. 1 root root 8 Apr 8 00:35 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Apr 11 2018 srv
dr-xr-xr-x. 13 root root 0 Apr 10 09:48 sys
drwxrwxrwt. 50 root root 4096 Apr 10 10:11 tmp
drwxr-xr-x. 13 root root 155 Apr 8 00:35 usr
drwxr-xr-x. 19 root root 267 Apr 8 00:39 var
root权限足够但是所有者权限不对,修改所有者777为root
[root@data /]# chown -R root root
[root@data /]# ll
total 28
lrwxrwxrwx. 1 root root 7 Apr 8 00:35 bin -> usr/bin
dr-xr-xr-x. 5 777 root 4096 Apr 8 00:39 boot
drwxr-xr-x. 20 root root 3260 Apr 10 09:48 dev
drwxr-xr-x. 76 root root 8192 Apr 10 09:48 etc
drwxr-xr-x. 3 root root 24 Apr 8 00:38 home
lrwxrwxrwx. 1 root root 7 Apr 8 00:35 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Apr 8 00:35 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 media
drwxr-xr-x. 2 root root 6 Apr 11 2018 mnt
drwxr-xr-x. 5 root root 50 Apr 8 18:27 opt
dr-xr-xr-x. 142 root root 0 Apr 10 09:48 proc
dr-xr-x---. 5 root root 4096 Apr 9 16:54 root
drwxr-xr-x. 24 root root 660 Apr 10 09:48 run
lrwxrwxrwx. 1 root root 8 Apr 8 00:35 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Apr 11 2018 srv
dr-xr-xr-x. 13 root root 0 Apr 10 09:48 sys
drwxrwxrwt. 50 root root 4096 Apr 10 10:11 tmp
drwxr-xr-x. 13 root root 155 Apr 8 00:35 usr
drwxr-xr-x. 19 root root 267 Apr 8 00:39 var
成功解决
[root@data .ssh]# ssh root@data
Last login: Sat Apr 10 10:15:28 2021 from data
[root@data ~]# exit
logout
Connection to data closed.