大网数据广告活动
服务器运维问答

How to display user@hostname in SSHD password prompt

· 52CE 我爱测

When I SSH to a server, the prompt sometimes displays my user and the hostname of the server: xavier@local:~$ ssh server1 xavier@server1's password: Sometimes all I get is Password: xavier@local:~$ ssh server2 Password: Which is …

问题原文

原帖链接 · Calimo · CC BY-SA 3.0

When I SSH to a server, the prompt sometimes displays my user and the hostname of the server:

xavier@local:~$ ssh server1
xavier@server1's password: 

Sometimes all I get is Password:

xavier@local:~$ ssh server2
Password: 

Which is less convenient when tunneling (difficult to know if I have to enter the password for the second server or if I need to repeat the first one because I made a mistake for instance), and also when using different usernames (did I forget to set the correct one in .ssh/config?).

Typically I find that Debian/Ubuntu will prompt with user@hostname's password:, whereas I see Password: on OpenSUSE/SLES/Mac servers.

Obviously the servers are configured differently, but I couldn't find what causes this difference. How can I configure the ssh server to display the user and hostname in the prompt? Or maybe I can do it client side?

已采纳解答

原帖链接 · Calimo · CC BY-SA 3.0

Investigating a bit further, it appears that the user@server's password prompt is used for password authentication, whereas the Password: prompt is the displayed for keyboard-interactive authentication. I wasn't aware that these two methods existed. They look pretty similar as they will typically both ask for a password.

So the trick is to:

  1. Make sure password authentication is enabled on the server. In /etc/ssh/sshd_config:

    PasswordAuthentication yes
    
  2. On the client side, set password as the preferred method

    ssh -o PreferredAuthentications=password server2
    

    It is sensible to add the keyboard-interactive method to the list in case the server has PasswordAuthentication disabled

    ssh -o PreferredAuthentications=password,keyboard-interactive server2
    

    I ended up adding the following to my .ssh/config:

    Host *
            ServerAliveInterval 120
            VerifyHostKeyDNS yes
            PreferredAuthentications publickey,password,keyboard-interactive
    

I am now getting the user@server's password: prompt on all hosts.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。