Why is my ssh connection dropping immediately after I enter my password?

There is a exit 0 in your .bash_profile file that provokes bash to exit. Remove it as it's not necessary:

ssh [email protected] sed -i '/exit\ 0/d' .bashrc .bash_profile .profile .login

I was facing the same problem..

but when i checked for the users, the user which i was using was not permitted to access SSH over the server.

So I recommend you to cross check the user permission that your user (david) is permitted to access SSH on server.