Skip to main content

TTY shells

·2 mins

My notes on some of useful tty commands #

Color when listing files #

export TERM=xterm-256-color 
alias ll='ls -lsahta --color=auto' 
Run: ll

Get interactive shell zsh shell // new kalli version working #

python3 -c 'import pty; pty.spawn("/bin/bash")' 
CTRL + Z 
stty raw -echo; fg 
enter 
export TERM=xterm-256color 
export SHELL=bash 
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/tmp 
stty rows X columns Y // get rows and columns info: stty -a 

Get interactive shell fully working (old version kali, not using zsh). #

ps -p $$ // check which if you are using bash, new version of kali uses zsh shells, it wont work. 
exec bash --login  // if command above returned zsh, change to bash. 

After using one of the methods, run below for tty #

crtz+z // on your keyboard 
run: stty raw -echo  // kali , if you run under zsh run on one line:  stty raw -echo; fg 
run: fg // kali 
hit enter  // target 
export TERM=xterm // target 
export SHELL=bash 
export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/tmp 
stty rows X columns Y // get rows and columns info: stty -a 

fix terminal exiting from the shell #

reset 

tty that work most of the time #

/usr/bin/script -qc /bin/bash /dev/null 
/usr/bin/script -qc /bin/sh /dev/null 

Python2 tty #

The sh shell version

python -c 'import pty; pty.spawn("/bin/sh")' 

The bash shell version

python -c 'import pty; pty.spawn("/bin/bash")' 

python3 tty #

python3 -c 'import pty; pty.spawn("/bin/bash")'