Super User is a question and answer site for computer enthusiasts and power users. 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

It's happened to me a few times now, that I want to shut down my own computer, grab the next best terminal (always have two dozen of them floating around), and type sudo halt, only to realize I've just shut down one of my servers because I didn't close the ssh connection I used half an hour ago.

I think the easiest way to tackle this would be to use my zshrc file to alias sudo halt to something else, depending on the hostname. I'm not sure whether you can use alias to do this, though. Any ideas?

share|improve this question
up vote 2 down vote accepted

I think a better solution would be to write a sudo rule that always requires a password to be entered for the 'halt' command. That should provide a good check, especially if you have a different password on the production servers.

I think the sudoers entry would look like this, but you may need to consult the manpage:

ALL (LOCALHOST) = PASSWD: /sbin/halt

share|improve this answer

The solution I use to avoid running commands in SSH hosts unaware of where I am running it, is to use a different prompt color when I ssh into another computer:

autoload -U colors && colors
if [[ $+SSH_TTY -eq 1 ]]; then
# define your prompt here
export PROMPT="$prompt_color %U%2v%u %~ %# %{${reset_color}%}"
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .