1

I configured my Raspberry Pi SSH-server to only accept ssh keys when logging in. Really clever I thought, until now.

The thing is, I've added a forced command for one key like this to authorized_keys:

command="cd /home/pi/Sites/" ssh-rsa [bla bla bla] [my comment]

And when trying to log in now, it says just

Connection to MYSITE closed.

What I presume is that the forced command is being run and after that no interactive shell is being launched and therefore the connection is closed. Is there any way to connect anyway and undo the changes I've done to the authorized_keys-file?

3
  • 2
    Easiest probably is to simply remove the SD card from the Pi, mount it somewhere and change that file. Commented Jun 14, 2017 at 17:03
  • Have you locked yourself out? You don't have another key? Or is it that you do have another, but wonder how you could proceed if you did not... Commented Jun 14, 2017 at 17:03
  • The Pi is at a remote location, so I can't access the SD card anyhow. Yes, you could really say I've locked myself out. I don't have any other keys on this particular computer, and the other computer with the other key is far away ... :p Commented Jun 14, 2017 at 17:06

1 Answer 1

1

What I presume is that the forced command is being run and after that no interactive shell is being launched and therefore the connection is closed.

Exactly.

Is there any way to connect anyway and undo the changes I've done to the authorized_keys-file?

No. This is a feature. If you would be able to override this, it would be going around security policy that you defined (well ... this exactly does not make a lot of sense).

As already pointed out, if you don't have different authorized key, different user with authorized keys or passwords, you will have to get to the remote location and modify that file physically on the SD card.

For the next time, if you want to cd to some directory and start interactive bash, you will need

command="cd /tmp/;bash" s
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! This was what I in the end believed as I read the documentation on forced commands on ssh.com. And if I just wanted the forced command to redirect to a directory of my choice and then launch an interactive shell like always, the way would be to append ; bash to the command?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.