I'm running CentOS Server 7 on a VM (ESXi) with root permissions. I have a bash script (in my /etc/profile.d/ directory) which is executed immediately after login. Before I created my .sh file in the directory there was no problem connecting to my VM via WinSCP. After creating the file and rebooting the system I cannot connect any longer. OpenSSH is installed.. Seems that the bash execution blocks the connection.. If I delete my .sh file via console afterwards the connection is established again. Is this a CentOS problem? Never had this issue under Ubuntu Server.

Error I'm getting:

Cannot initialize SFTP protocol. Is the host running a SFTP server?

Any ideas? Thank you in advance!

  • 1
    What's in that script? – Eugen Rieck Apr 16 '18 at 10:58
  • I could post what's inside the script, but it's hundreds of lines.. Never had problems with it under Ubuntu Server.. Even if it contains some errors, this should not block the connection? – P4tR Apr 16 '18 at 11:10
  • It's your responsibility to post Minimal, Complete, and Verifiable example. Until you do so, you cannot get any better answer than @tripleee has posted (what is most probably the correct answer). + Why do you think that error cannot block the connection? – Martin Prikryl Apr 16 '18 at 11:12
  • You are right.. I replaced the script content with a simple echo for testing.. And this time the connection is not blocked.. So it's the scripts fault.. Thanks for your help! – P4tR Apr 16 '18 at 11:59

You are not showing us your script, so this is obviously somewhat speculative; but most probably your script should not be in profile.d because it requires some sort of user interaction.

The profile should be reserved exclusively for things which need to run even in noninteractive sessions.

The proper place for interactive functionality is probably not in your login scripts at all, but something like this e.g. in your $HOME/.bash_profile can at least avoid producing damage for noninteractive sessions.

case $- in *i*) invoke your script here;; esac

If you have a .bash_profile already, it may well already contain a case $- statement which you can amend instead of adding a second one.

  • I moved my script from /etc/profile.d to my $HOME dir. Now it's executed by .bash_profile and WinSCP can connect without a problem. Thank you! – P4tR Apr 16 '18 at 12:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.