CentOS 7: Can't connect via WinSCP when bash is executed

-1

1

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!

P4tR

Posted 2018-04-16T10:56:15.150

Reputation: 1

1What's in that script? – Eugen Rieck – 2018-04-16T10:58:35.127

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 – 2018-04-16T11:10:39.927

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 – 2018-04-16T11:59:14.517

Answers

1

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.

tripleee

Posted 2018-04-16T10:56:15.150

Reputation: 2 480

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 – 2018-04-16T12:27:02.287