Cannot log into server via SSH anymore


#1

I installed Gogs the other day and configured it.

Inside the config I set the user to “gogs”, the SSH port to my servers SSH port and everything worked perfectly fine.

However I just tried to SSH into my server and received the following error:

PTY allocation request failed on channel 0
2018/10/30 12:16:11 [FATAL] [...g/setting/setting.go:589 NewContext()] Expect user 'gogs' but current user is: root
Connection to XXX.XXX.XXX.XXX closed.

Had to boot up a recovery system because I had no other way of accessing the server. I tried to change the user to “root” but then received an error upon login, telling me that I authenticated correctly but gogs prevents the Login.

Then I though okay, ill just disable the SSH inside gogs. Well, I did that but I still can’t SSH into my server because now gogs prevents it and says SSH is disabled.

Is there anyway I can disable gogs’ SSH in a way I can still SSH into my server? I really don’t wanna kick out gogs but SSH is a must.


#2

This is exactly why Gogs checks the run user, to give a hard time to setup a user other than root. If you can’t access the machine with password, it is most likely you lost control to your machine. I think most VPS provider has serial port console as kind of “recovery mode”.


#3

Hey, thanks for the reply!

That’s not my issue. Well, first off I don’t have password access set up on my server.
I use SSH Keys. It isn’t a VPS either.

However as I said, that’s not the problem. I can easily boot up the recovery system.
My question is how do I run gogs while still being able to SSH into my Server (with SSH keys).

What configuration is needed?

I really like gogs and I appreciate your work very much!
But if I can’t SSH into my server while gogs is set up I simply cannot continue hosting a gogs instance.
I really do not want to switch to a different git system.
That’s why I asked here in the first place.

So to clarify:
What am I supposed to enter in the gogs configuration to use gogs while still being able to SSH into my server?


What I’ve tried so far:

  • Disabling SSH in the gogs config.

    • –> results in gogs telling me I cant SSH into my server
  • Setting a different user (other than root)

    • –> results in gogs throwing the error "Expect user 'x' but current user is: root"
  • Setting root as user and enabling SSH

    • –> results in gogs telling me I authenticated successfully but cannot log in
  • Setting up a different port

    • –> same as above

What am I supposed to configure so that I can still SSH into my server normally while running gogs?

Thanks in advance! :smile:


#4

You must run Gogs in a different user, ideally, name “git”. This is how it works with OpenSSH server.

The “git” is a real linux user, not just you set a string in Gogs’s configuration. And start Gogs under that user.


#5

Alright! Perfect, ill try that. Thank you (:

Just one more thing: Gogs appears to add itself to the autostart (ubuntu server)
So in order to run gogs as a different user, I need to know where gogs adds itself to the autostart and disable that temporarily.

I already checked /etc/init.d/ and the crontab file but no gogs there what so ever.

I also tried to move the gogs binary temporarily. But that fails with the error:

PTY allocation request failed on channel 0
bash: /path/to/my/gogs: No such file or directory

Where can I disable the autostart for gogs on my ubuntu server?


#6

Never mind. After looking through every single init script, profile config, startup daemons, bachrc scripts and cron files I finally found it in the SSH Keys of my root user (/root/.ssh/authorized_keys)