Messed up my .bash_profile remotely, can't ssh back in
Solution 1:
As described here you can use
ssh -t user@host bash --noprofile
in fact, as @JoL suggests, you don't even need the --noprofile
, since when ssh executes bash as just another command, it's not considered a login shell. Running ssh -t user@host bash
will only read the RC files; and running ssh -t user@host bash --norc
will not read even those.
Solution 2:
Try to SSH and run sh
instead of bash
, e.g.
ssh user@host sh
Then rename (mv
) or edit the broken file (ex/vi
).
Solution 3:
Run ssh -t host vi .bash_profile
(or the editor of you choice in place of vi
) and fix your .bash_profile
.
(The -t
option may not be needed, depending on which editor you choose.)
If you know exactly what needs to be fixed, you may be able to fix it non-interactively. For example, something like
printf 's/exec foo/. foo/\nwq\n' ssh host ed .bash_profile