Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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
     prompt_color=%{$fg[green]%}
else
     prompt_color=%{$fg[red]%}
fi
# define your prompt here
export PROMPT="$prompt_color %U%2v%u %~ %# %{${reset_color}%}"
share|improve this answer

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.