首页 > 代码库 > centos7 配置ssh 免密码登陆
centos7 配置ssh 免密码登陆
我只有一台机器,是因为要配置hadoop分布式环境用,需要配置ssh
两个用户: zhangxs, root
首先在切换到zhangxs用户下
执行【 ssh-keygen -t rsa】
[zhangxs@zhangxs Desktop]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/zhangxs/.ssh/id_rsa): Created directory ‘/home/zhangxs/.ssh‘. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/zhangxs/.ssh/id_rsa. Your public key has been saved in /home/zhangxs/.ssh/id_rsa.pub. The key fingerprint is: 0f:4b:e9:0f:72:01:a5:57:ea:2e:9b:39:3a:0e:66:4d zhangxs@zhangxs The key‘s randomart image is: +--[ RSA 2048]----+ | . . | | o o | | o o | | + . | | E S | | o + = | | + . o * . | | o .. .B o | | .oo+. . | +-----------------+
默认会在当前用户的home/$用户名 目录下生成一个.ssh文件夹,这个是隐藏文件夹
cd /home/zhangxs/ 切换到文件夹下,输入 [ll -a]
[zhangxs@zhangxs ~]$ ll -a
total 36
drwx------. 22 zhangxs zhangxs 4096 3月 19 14:48 .
drwxr-xr-x. 3 root root 21 3月 18 17:50 ..
drwx------. 3 zhangxs zhangxs 26 3月 18 23:06 .adobe
-rw-------. 1 zhangxs zhangxs 470 3月 19 14:50 .bash_history
-rw-r--r--. 1 zhangxs zhangxs 18 8月 3 2016 .bash_logout
-rw-r--r--. 1 zhangxs zhangxs 193 8月 3 2016 .bash_profile
-rw-r--r--. 1 zhangxs zhangxs 231 8月 3 2016 .bashrc
drwx------. 17 zhangxs zhangxs 4096 3月 18 20:59 .cache
drwxr-xr-x. 19 zhangxs zhangxs 4096 3月 18 20:08 .config
drwxr-xr-x. 4 root root 48 3月 19 01:00 datainfo
drwxr-xr-x. 2 zhangxs zhangxs 220 3月 19 14:22 Desktop
drwxr-xr-x. 2 zhangxs zhangxs 6 3月 18 18:00 Documents
drwxr-xr-x. 2 zhangxs zhangxs 51 3月 19 00:00 Downloads
-rw-------. 1 zhangxs zhangxs 16 3月 18 18:00 .esd_auth
-rw-------. 1 zhangxs zhangxs 1554 3月 19 14:12 .ICEauthority
drwxrwxr-x. 3 zhangxs zhangxs 19 3月 18 18:24 .java
drwx------. 3 zhangxs zhangxs 19 3月 18 18:00 .local
drwx------. 3 zhangxs zhangxs 26 3月 18 23:06 .macromedia
drwxr-xr-x. 5 zhangxs zhangxs 54 3月 18 18:04 .mozilla
drwxr-xr-x. 2 zhangxs zhangxs 6 3月 18 18:00 Music
drwxr-xr-x. 4 zhangxs zhangxs 89 3月 18 23:21 Pictures
drwxrw----. 3 zhangxs zhangxs 19 3月 19 01:08 .pki
drwxr-xr-x. 2 zhangxs zhangxs 6 3月 18 18:00 Public
drwxr-xr-x. 3 zhangxs zhangxs 17 3月 18 18:00 .redhat
drwx------. 4 zhangxs zhangxs 48 3月 18 18:26 .speech-dispatcher
drwx------. 2 zhangxs zhangxs 80 3月 19 14:49 .ssh
drwxr-xr-x. 2 zhangxs zhangxs 6 3月 18 18:00 Templates
drwxr-xr-x. 2 zhangxs zhangxs 6 3月 18 18:00 Videos
【cd .ssh】 文件下,有两个文件
-rw-------. 1 zhangxs zhangxs 1675 3月 19 14:48 id_rsa -rw-r--r--. 1 zhangxs zhangxs 397 3月 19 14:48 id_rsa.pub
【cp id_rsa authorized_keys】 复制文件
【ssh localhost】 以ssh方式登陆localhost,执行完后会在当前目录下生成两个文件
[zhangxs@zhangxs .ssh]$ ssh localhost The authenticity of host ‘localhost (127.0.0.1)‘ can‘t be established. ECDSA key fingerprint is 83:99:8a:10:0b:f3:5d:7f:35:95:1b:db:67:3e:b4:68. Are you sure you want to continue connecting (yes/no)? y Please type ‘yes‘ or ‘no‘: yes Warning: Permanently added ‘localhost‘ (ECDSA) to the list of known hosts. Last login: Sun Mar 19 14:12:31 2017
--------------------------------------------------------------------------------------------
因为是要配置为分布式,所以要root用户到zhangxs用户,
首先要看在在hosts中是否配置好
[zhangxs@zhangxs .ssh]$ more /etc/hosts 127.0.0.1 localhost 192.168.177.120 hadoop-zhangxs.com zhangxs
网卡中是否配置好(如果网卡中没有配置,在ssh zhangxs 时会报错:([root@zhangxs .ssh]# ssh zhangxs
ssh: connect to host zhangxs port 22: Connection timed out)
[root@zhangxs sbin]# ifconfig enp1s0f0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.177.120 netmask 255.255.255.0 broadcast 192.168.177.255 ether f8:a9:63:04:42:7e txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 18
这两个都没问题就可以,切换到root用户 执行【 ssh-keygen -t rsa】
后面步骤都一样拉!!!!!!!!!
centos7 配置ssh 免密码登陆
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。