[Solved]-SSH into Django Shell

17👍

Pass the -t option to ssh.

Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

By default, running ssh host command doesn’t allocate a proper pseudo-tty, which makes any program that uses terminal escape routines, such as line-editing interpreters, etc. fail.

Therefore, your one-liner can be:

ssh -t -i mysite.pem root@remotehost python /usr/local/myapp/manage.py shell

It is possible to, but no need to wrap in another layer of bash like you did. Remember that ssh host command actually passes command as a string to the user’s default shell (which is why you can do shell-specific things like cd), so I can’t think of a reason why you’ll need to run bash within bash.

Leave a comment