SFTP password expire error

Hi,

I am using sftp in batch script for which all configuration for public/private keys are done and it works fine without asking a password. No issues till this point. Now I the problem I have is that if the password expires/someone changes the authentication keys at reote server then the scripts asks for the password prompt and the process waits there. No error is thrown, it just stop with asking a password.

I want to handle these kind of scenarios so that if any of the above situation (password expires/someone changes the authentication keys) occur then some error should result or I should get proper exit status.

Thanks for your help.

The -b batchfile option should convince it the session's completely noninteractive and fail instead of prompting.

I tried -b option as:

sftp -b commands.sh user@server

command.sh looks like:

put file.txt
bye

It works fine if proper setup of keys is done. If I play around the key than again it wait with password prompt.

Then I chaged the main script as:
sftp -b commands.sh server

but then i have new problem that it tries to connect with the user from which I am currently logged in which actually is not the correct user to connect with and this is obvious error.

Any suggestions?

You can put this into your ~/.ssh/config file:

Host server
    User user
    PasswordAuthentication no

This means, that for connections to "server" use the username "user" and do not use password authentication.

1 Like

wow...that worked pretty well...

Thanks alot hergp/Corona688...