当你运行没有login_name参数的ssh时,它会自动使用你的本地用户名作为login_name。 例如:
cogan@localhost$ ssh myserver cogan@myserver's password:
有没有办法强制SSH提示login_name?
如果你在谈论OpenSSH,答案是否定的(你可以查看源代码 )。 正如@cnicutar指出的,你可以使用ssh user@host
或者在.ssh/config
configuration别名
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 ~/.bashrc
或source /etc/bashrc
)。
然后,像ssh
一样运行它:
[ 12:49 jon@hozbox ~ ]$ ssh localhost Enter your username: bob bob@localhost's password: [ 12:50 bob@hozbox /home/bob ]$
所以我有同样的问题。 我正在使用CMD
ssh "IP address" ssh 000.000.000.0
它立即要求input不存在的用户密码(我的电脑名称)。
真正简单的解决方法就是使用这个命令:
ssh root@"IP address" ssh [email protected]
你可以用你想要的任何用户名replaceroot。 这将导致服务器提示您input您想要的用户名的密码。