无法解析ssh的别名

这是我的问题:

  • 我在同一网络192.168.122.0/24中有两台机器

我的/ etc / hosts:

192.168.122.100 toto 192.168.122.110 tata 

如果我输入: ssh toto

 root@toto's password: Permission denied (publickey,password).` 

但如果我键入ssh toto@192.168.122.100它可以工作..

问题是什么?

您必须指定远程用户,否则它将使用您在本地登录的用户。

例如:

 ssh username@host 

所以,在你的情况下你会使用:

 ssh toto@toto 

首先,您是否在/ etc / ssh / sshd_config(托托主机)上检查了这些指令?

 AllowUsers root toto PermitRootLogin yes 

如果是生产环境,我强烈建议以这种方式设置这些指令:

 AllowUsers toto Port 2233 PermitRootLogin no 

避免root访问并设计除22以外的其他端口。它更安全。

如果您想在没有密码提示的情况下访问本地网络主机,请按照下面的步骤操作(假设totXX =主机客户端,totYY =主机服务器ssh):

  1. 使用相同的密码在所有计算机(Ex:toto)中创建相同的用户;

  2. 在totXX上生成公钥

     # may output a message like this: toto@totXX:~> ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/toto/.ssh/id_rsa): Created directory '/home/toto/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/toto/.ssh/id_rsa. Your public key has been saved in /home/toto/.ssh/id_rsa.pub. The key fingerprint is: 3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 toto@totXX 
  3. 在totYY上创建〜/ .ssh目录

     toto@totXX:~> ssh toto@totYY mkdir -p .ssh toto@totYY password: 
  4. 将totXX公钥放在totYY上:

     toto@totXX:~> cat .ssh/id_rsa.pub | ssh toto@totoYY 'cat >> ssh/authorized_keys' toto@totoYY password: 
  5. 在totYY上重新启动ssh服务:

     toto@totXX:~> sudo service ssh restart 
  6. 如果一切正常,则不会在ssh访问时请求密码。

     toto@totoXX:~> ssh toto@totoYY toto@totYY:~>