Just guessing, but Net::SSH::Expect may be unable to detect failed logins: It tries to log once, assumes login was successful and starts sending commands to be executed by the remote shell when actually, the SSH process is still at the login prompt. That will explain why you get the error delayed.