Skip to content

Instantly share code, notes, and snippets.

@afriza
Created December 22, 2022 10:08
Show Gist options
  • Save afriza/0c2e9263e28ea42fb542f485e4dd704f to your computer and use it in GitHub Desktop.
Save afriza/0c2e9263e28ea42fb542f485e4dd704f to your computer and use it in GitHub Desktop.
Run mtr without sudo by using SUID bit
#! /bin/sh
# Optional: if not already in $PATH
ln -s /usr/local/Cellar/mtr/0.95/sbin/mtr /usr/local/sbin/
ln -s /usr/local/Cellar/mtr/0.95/sbin/mtr-packet /usr/local/sbin/
# or on newer macOS/Homebrew
ln -s /opt/homebrew/Cellar/mtr/0.95/sbin/mtr /opt/homebrew/bin/
ln -s /opt/homebrew/Cellar/mtr/0.95/sbin/mtr-packet /opt/homebrew/bin/
# A quick and dirty way to run mtr without sudo by using SUID bit.
# There are security risks when there are bugs in mtr.
sudo chown root `command -v mtr-packet`
sudo chmod u+s `command -v mtr-packet`
# Reference:
# - https://blog.dave-bell.co.uk/2020/01/06/using-mtr-on-os-x-without-sudo/
# - Why mtr needs sudo/root-access? https://github.com/traviscross/mtr/issues/204#issuecomment-723961118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment