I'm being automatically logged out immediately after login.


One of my usernames logs out immediately after login. When logging in through .ssh I get an error saying Permission denied (publickey,password). When logging in through the console I am immediately logged out.

All the other usernames, including root, are working fine.

How can I fix this issue?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I faced a similar situation. When I successfully log on to the server, the server closes my login session. ssh does not work, you can only use the recovery console. This situation started when I deleted the shell package that named Fish.

  1. Turn off your droplet.
  2. Go to recovery section and select boot mode to “Recovery ISO”.
  3. Turn on your droplet and run “Recovery console”.
  4. Mount your disk. (Command 1);
  5. Go to “Interactive shell” (Command 6);
  6. Go to your system’s etc folder with this way: ~/../mnt/etc
  7. Open .profile file with your terminal editor (VIM, nano);
  8. Edit shell path to default shell path (/bin/bash)
  9. Turn off droplet and return to mode “Boot from hard driver”.

Wow, that worked immediately. I had searched the net for days, but in the future I’ll ask here immediately.

Thank you

It sounds to me like this user may have an invalid shell set. When you log into Linux on the command line it will execute the assigned shell for that user and that is where your session occurs. When you type exit it closes the shell and your connection terminates. If you have an invalid shell set, your droplet will attempt to start what is defined, find it cannot and exit.

You can ensure the correct shell is set for the user by running the following as root:

usermod --shell /bin/bash your_username

for bash or

usermod --shell /bin/sh your_username

for sh.