问题记录:ubuntu中ssh配置

开始出现问题:

ubuntu@ip-172-31-30-98:$ ssh-copy-id ubuntu@ip-172-31-30-98
/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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Permission denied (publickey).

设置密码:

ubuntu@ip-172-31-30-98:~$ sudo passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

更新sshserver

ubuntu@ip-172-31-30-98:~$ sudo apt-get update

ubuntu@ip-172-31-30-98:~$ sudo apt-get install openssh-server

删除根目录下的.ssh文件夹然后重新生成密钥

ubuntu@ip-172-31-30-98:~$ rm -r .ssh
ubuntu@ip-172-31-30-98:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): 
Created directory '/home/ubuntu/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
The key fingerprint is:
f1:95:00:ba:da:5e:52:0e:9e:4d:7c:c6:48:dc:5d:70 ubuntu@ip-172-31-30-98
The key's randomart image is:
+--[ RSA 2048]----+
|        ... ..E  |
|       o . o +   |
|      . + . +    |
|       + = .     |
|      o S =      |
|     + B o       |
|    . = +        |
|     . o         |
|      .          |
+-----------------+
ubuntu@ip-172-31-30-98:~$ 
ubuntu@ip-172-31-30-98:~$ ssh-copy-id localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is f3:d8:39:64:a5:30:d7:2c:b0:c7:38:ba:4c:85:01:de.
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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ubuntu@localhost's password: 

//输入密码回车,直到结束。

测试 :

ubuntu@ip-172-31-30-98:~$ ssh ubuntu@ip-172-31-30-98
The authenticity of host 'ip-172-31-30-98 (172.31.30.98)' can't be established.
ECDSA key fingerprint is f3:d8:39:64:a5:30:d7:2c:b0:c7:38:ba:4c:85:01:de.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ip-172-31-30-98,172.31.30.98' (ECDSA) to the list of known hosts.
ubuntu@ip-172-31-30-98's password: 
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)

********************

成功

********************

如果仍出现

ubuntu@ip-172-31-23-126:~$ ssh-copy-id localhost
/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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Permission denied (publickey).

则采用手动的方式:

ubuntu@ip-172-31-23-126:~$ cd .ssh
ubuntu@ip-172-31-23-126:~/.ssh$ ls
id_rsa  id_rsa.pub  known_hosts
ubuntu@ip-172-31-23-126:~/.ssh$ cat id_rsa.pub >> authorized_keys

测试:

ubuntu@ip-172-31-23-126:~/.ssh$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
ubuntu@ip-172-31-23-126:~/.ssh$ ssh ubuntu@ip-172-31-23-126
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)


 * Documentation:  https://help.ubuntu.com/

*********************

成功

********************

与其他节点的ssh

ubuntu@ip-172-31-23-126:~/.ssh$ ssh-copy-id ubuntu@ip-172-31-30-98
The authenticity of host 'ip-172-31-30-98 (172.31.30.98)' can't be established.
ECDSA key fingerprint is f3:d8:39:64:a5:30:d7:2c:b0:c7:38:ba:4c:85:01:de.
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: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ubuntu@ip-172-31-30-98's password: 


Number of key(s) added: 1


Now try logging into the machine, with:   "ssh 'ubuntu@ip-172-31-30-98'"
and check to make sure that only the key(s) you wanted were added.

测试:

ubuntu@ip-172-31-23-126:~/.ssh$ ssh ubuntu@ip-172-31-30-98
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)


 * Documentation:  https://help.ubuntu.com/

**************

成功

**************

如果仍出现Permission denied (publickey).问题,解决如下:

ubuntu@ip-172-31-27-146:~/.ssh$ sudo vim /etc/ssh/sshd_config

PasswordAuthentication yes(no改为yes保存)

ubuntu@ip-172-31-27-146:~/.ssh$ cd /etc/init.d/

ubuntu@ip-172-31-27-146:/etc/init.d$ service ssh restart

测试:

ubuntu@ip-172-31-27-146:~$ ssh ubuntu@ip-172-31-30-98
The authenticity of host 'ip-172-31-30-98 (172.31.30.98)' can't be established.
ECDSA key fingerprint is f3:d8:39:64:a5:30:d7:2c:b0:c7:38:ba:4c:85:01:de.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ip-172-31-30-98,172.31.30.98' (ECDSA) to the list of known hosts.
ubuntu@ip-172-31-30-98's password: 
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)


 * Documentation:  https://help.ubuntu.com/

****************

成功

***************

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值