A tiny shell script that generates a Plex authentication token using Plex's device-link flow — no username/password, nothing sent to any third party. It's a CLI port of the browser-based plex-token-generator.
bashcurljq
./plex-token.shYou'll be asked for a product name (press Enter for the default). The script then prints a link with the PIN already filled in:
Open this to authorize (PIN is pre-filled):
https://plex.tv/link?pin=ABCD
Or go to https://plex.tv/link and enter: ABCD
Open the first URL in any browser, sign in to Plex if needed, and confirm. The second line is there for when you're authorizing from another device and have to type the PIN by hand.
The script polls every 5 seconds and prints your token once you've authorized:
Success! Your Plex token:
xxxxxxxxxxxxxxxxxxxx
The PIN expires after a few minutes (the script tells you exactly how long); just re-run if it lapses.
Status messages go to stderr and the bare token goes to stdout, so you can capture just the token:
./plex-token.sh > token.txtPOST https://plex.tv/api/v2/pins— requests a PIN tied to a freshly generated client identifier (so Plex treats each run as a new device).- You authorize the PIN at
https://plex.tv/link. GET https://plex.tv/api/v2/pins/{id}— polled until it returns yourauthToken.
A CLI port of ndm13/plex-token-generator, which implements the same Plex device-link flow as a browser app. Licensed under the MIT License.