Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally locked myself out of my server. I changed the port, added ssh-keys, PermitRootLogin is 'no' and if I remember correctly PasswordAuthentication is also no. Logging in on another server works fine so the problem isn't due to my local ssh-keys.

When logging in via ssh -vv -p 2345 username@ I get the following info back.

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 102: Applying options for *
debug1: Connecting to [] port 1234.
debug1: Connection established.
debug1: identity file /Users/yoeriboven/.ssh/id_rsa type 1
debug1: identity file /Users/yoeriboven/.ssh/id_rsa-cert type -1
debug1: identity file /Users/yoeriboven/.ssh/id_dsa type -1
debug1: identity file /Users/yoeriboven/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
Connection closed by

I luckily can still login via FTP so I backed up all the files but I only have access to the user's folder.

Any idea how I could login? If not, I'll have to destroy the server and set it up all over.

share|improve this question
If this is some kind of hosted server, then there should be some kind of rescue mechanism. You could boot into the rescue system and then fix the problem by manually mounting the hard disk, figuring out what went wrong (look in /var/log/auth.log or whatever log your distribution is using for ssh) and then resolve the issue in the configuration files. – Martin von Wittich Jan 21 '14 at 10:54
@yoeriboven, it is customary on SE to accept an answer. If your question is still unanswered then please add additional information to your question. – bsd Jan 27 '14 at 10:47

If you've already generated a pair of ssh keys, you just need to copy one to the remote server. If you haven't generated keys yet you can do so via ssh-keygen -t rsa

Since you have ftp access to your user's directories, ftp and copy the public key.
Normally one would want to append their key id_rsa.pub to the remote authorized_keys but since you can't login and can only ftp, you'll have to clobber any existing file.

ftp remoteserver, login with username and password Then you want to copy /Users/yoeriboven/.ssh/id_rsa.pub to the remote server's /Users/yoeriboven/.ssh/authorized_keys

ftp will let you create directories in case there is no remote /Users/yoeriboven/.ssh dir, etc

Then you should be able to login using the ssh command.

Another path would be to login using a live (rescue) cd and change your sshd_config to allow passwords and reboot. The ftp solution will allow restoration without a reboot.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.