Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On a remote machine I changed my zsh settings and it is now broken,
for every keypress it says: "url-quote-magic:1: url-quote-magic: function definition file not found "

I don't have another account on that machine, What can I do to disable the faulty .zshrc so that I can use my shell again and fix it.

share|improve this question
add comment

5 Answers

up vote 12 down vote accepted

You can run a command on the remote server without logging in like this:

ssh -lUSERNAME SERVER COMMAND

e.g.

ssh -lsomeuser someserver 'mv .zshrc .zshrc.bak'

The command given as last argument to ssh will be executed by a non-interactive shell and commands from .zshrc are only executed by interactive shells (see zsh manpage, section on startup and shutdown files).

share|improve this answer
    
Yes that works fine! Thanks. Although I use a "key" to login and for me it looks like: ssh servername 'mv .zshrc .zshrc.broken' –  Ali Feb 1 '12 at 19:12
add comment

I could also sftp to the server and overwrite the .zshrc with an empty file or with one that works!

share|improve this answer
add comment

Here, it's easy because the file you've messed up is only used by interactive logins. If you'd messed up ~/.zshenv, or if your login shell was bash and you'd messed up ~/.bashrc (weirdly, bash reads ~/.bashrc if it's a non-interactive login shell and its parent is rshd or sshd), none of the methods that rely on executing a command non-interactively would work.

SSH insists on running a shell. If you have no other way to log in (via another account or via a method other than ssh), then your only recourse is to press Ctrl+C really fast after you're authenticated and before the shell reaches the problematic line. In practice, this can often be done manually; it may help to arrange for the machine to be heavily loaded (CPU or disk). If you have trouble pressing the keys at the right time, try using expect.

share|improve this answer
add comment

I could have changed my shell to bash using:

ssh -luser server 'chsh -s /bin/bash'  

assuming bash is available on the sever and it works for me.

share|improve this answer
add comment

I tried to do a remote edit with vim:

vim sftp://user@server/.zshrc

which didn't work. Although :Nread sftp://server/.zshrc could load the broken .zshrc file and :Nwrite could write it back (I have my public key on the server and ssh without a password).

Still more solutions are very welcome.

share|improve this answer
add comment

Your Answer

 
discard

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.