强制ssh提示用户

当你运行没有login_name参数的ssh时,它会自动使用你的本地用户名作为login_name。 例如:

cogan@localhost$ ssh myserver cogan@myserver's password: 

有没有办法强制SSH提示login_name?

如果你在谈论OpenSSH,答案是否定的(你可以查看源代码 )。 正如@cnicutar指出的,你可以使用ssh user@host或者在.ssh/configconfiguration别名

 Host meh HostName foo User bar 

然后ssh meh

由于ssh没有强制用户名提示的选项, 您可以在~/bin目录下创build以下脚本,并将其命名为ssh

 #!/usr/bin/perl my $user_at_address = $ARGV[0]; my @u_a = split(/@/, $user_at_address); if (defined $u_a[1]) { if ( $^O == 'linux' ) { exec ("/usr/bin/ssh $u_a[0]\@$u_a[1]"); } if ( $^O == 'solaris' ) { exec ("/usr/local/bin/ssh $u_a[0]\@$u_a[1]"); } } else { print "Enter your username: "; my $username = <STDIN>; chomp ( $username ); if ( $^O == 'linux' ) { exec ("/usr/bin/ssh $username\@$u_a[0]"); } if ( $^O == 'solaris' ) { exec ("/usr/local/bin/ssh $username\@$u_a[0]"); } } 

然后,使脚本可执行:

 chmod 755 ~/bin/ssh 

确保你的PATH$HOME/bin (把export PATH=$HOME/bin:$PATH放在~/.bashrc/etc/bashrc/etc/bashrc source ~/.bashrcsource /etc/bashrc )。

然后,像ssh一样运行它:

 [ 12:49 jon@hozbox ~ ]$ ssh localhost Enter your username: bob bob@localhost's password: [ 12:50 bob@hozbox /home/bob ]$ 

我不这么认为 – 如果是这样,那将是通过.sshconfig

http://linux.die.net/man/5/ssh_config

你可以尝试设置用户非法的东西,看看它做什么。

所以我有同样的问题。 我正在使用CMD

 ssh "IP address" ssh 000.000.000.0 

它立即要求input不存在的用户密码(我的电脑名称)。

真正简单的解决方法就是使用这个命令:

 ssh root@"IP address" ssh [email protected] 

你可以用你想要的任何用户名replaceroot。 这将导致服务器提示您input您想要的用户名的密码。