Skip to main content

A production warning banner, safer aliases and a colour prompt for every login

Drop-in files in /etc/profile.d/ apply to every user's login shell. Here are three small ones.

1. Safer aliases: /etc/profile.d/custom-aliases.sh

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'

These only affect interactive shells, not scripts.

2. Production warning: /etc/profile.d/custom-prod-warning.sh

Show it only on hosts that really are production. If every box shows it, people learn to ignore it.

[[ $- == *i* && -t 0 && -t 1 ]] || return
grep -qx "$(hostname -s)" /etc/production-hosts 2>/dev/null || return
RED='\033[1;31m'; NC='\033[0m'
if command -v figlet >/dev/null; then
  figlet -f big PRODUCTION | while IFS= read -r l; do printf "${RED}%s${NC}\n" "$l"; done
else
  echo -e "${RED}***** PRODUCTION SERVER *****${NC}"
fi
echo -e "${RED}This is a LIVE system. Think twice before running commands.${NC}"

3. Two-line colour prompt: /etc/profile.d/custom-prompt-and-colors.sh

if [[ $- == *i* && -t 0 && -t 1 && -z ${SSH_ORIGINAL_COMMAND:-} ]]; then
  R=$(tput sgr0); B=$(tput bold); G=$(tput setab 8)
  RED=$(tput setaf 1); MAG=$(tput setaf 5); GRN=$(tput setaf 2); CYN=$(tput setaf 6)
  PS1="\n\[$B$G$RED\]\u\[$MAG\]@\[$RED\]\h\[$GRN\] : \d \t\[$R\]\n\[$CYN\][\w]\[$R$B\] \\$ \[$R\]"
  export PS1
fi
  • Wrap every colour code in \[ \], or line editing gets confused.
  • The -t and SSH_ORIGINAL_COMMAND checks keep scp, rsync and Ansible sessions clean. Any output from profile scripts breaks them.

Notes

  • tailf was removed from util-linux; use tail -f.
  • Files are read in alphabetical order; prefix them (zz-) if order matters.