August 31, 2009

Solution to error “command-line: line 0: Bad configuration option: PermitLocalCommand”

Filed under: Tips — Tags: — Webopius @ 8:56 pm

Sorry for the slightly geeky title but that’s the error I started receiving recently on two of our Ubuntu Linux servers whenever we tried to rcp, scp or sftp from the server to any other remote system.

A command such as this: sftp would produce the error:

command-line: line 0: Bad configuration option: PermitLocalCommand
Couldn’t read packet: Connection reset by peer

Honestly, nothing on the server had changed, no installs, no upgrades, no configuration changes. The rcp command was used within a cron batch file that handled site backups. One week it was working, then it just failed… I know, you don’t believe me!

Anyway, after some time spent in Google, the problem seemed to be that our /usr/bin/ssh was incompatible with the sftp and scp commands.

Each time a command like ‘sftp’ is called, it automatically adds a hidden parameter ‘PermitLocalCommand=no’ and then calls ssh (usually /usr/bin/ssh). In our case, our /usr/bin/ssh command had no idea what ‘PermitLocalCommand’ meant and simply rejected it.

If you are having the same problem, try something like this directly to your ssh command:

ssh -oPermitLocalCommand=no

If ssh returns an error, then you probably have the same issue as we had.

The fix

In our case, the fix was really simple. We just removed and re-installed the open-ssh client code as follows:

sudo apt-get remove openssh-client
sudo apt-get install openssh-client

Then, all returned to normal.

  • Tags