What does su do?

switch to another user and start a shell (defaults to root).

▸ Explain your own su command →

su examples, explained

$ su

  • suswitch to another user and start a shell (defaults to root)

$ su - alice

  • suswitch to another user and start a shell (defaults to root)
  • -an argument passed to the command
  • alicean argument passed to the command

$ su -c 'systemctl restart nginx'

  • suswitch to another user and start a shell (defaults to root)
  • -crun this single command as the target user, then exit
  • systemctl restart nginxvalue for -c

$ su -s /bin/bash postgres

  • suswitch to another user and start a shell (defaults to root)
  • -srun this shell instead of the target user's default
  • /bin/bashvalue for -s
  • postgresan argument passed to the command

su flags & options

-lstart a login shell, giving the target user's full environment
-crun this single command as the target user, then exit
-srun this shell instead of the target user's default
-ppreserve the current environment instead of resetting it

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.