a year ago
Can i run linux commands on railway shell?
5 Replies
a year ago
What are you trying to do, which linux commands do you want to run? If you right-click the service and select "Copy SSH", that should give you access to the container and some, not all commands may work
a year ago
Hi, Yes you have several ways to run shell commands against your Railway project.
- One‑off commands (local, with your remote ENV):
# link your local folder to the Railway project (if needed)
railway link
# run any command with your RAILWAY_* env vars injected
railway run <your-command>
# e.g. run bash:
railway run bash
# or run a migration:
railway run python manage.py migrate
2.Interactive shell (local):
railway shell
This drops you into a bash session with all your project’s env vars set.
- SSH into the container (true “in‑production” shell):
- In Station, open your service → click the ••• menu → Copy SSH.
- On your terminal, run:
ssh -i /path/to/railway_key railway@<container-host>
- You’re now inside the live container run
ls, inspect files, etc. - Automate on every deploy:
• In Station → your service → Settings → Deploy
• Under Pre‑deploy Steps (or Custom Start Command), add any shell commands you want run before the app starts
• Save & redeploy Railway will execute them automatically
TL;DR:
• railway run for quick, one‑off commands with your prod env.
• railway shell for a full interactive local shell.
• SSH for inside‑container access.
• Pre‑deploy steps to bake commands into each deployment.
Following this steps you can run run linux commands on railway shell.
a year ago
I hope it can help you.