Reputation: 11
When I execute a command through SSH from a computer to my Linux server it doesn't save in its bash history.
I have my .bash_profile set like this:
[USER@ /home/USER]2 $cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
# Will Give me ip of person logged in
WHOAMI=`who -m | cut -d '(' -f 2| cut -d ')' -f1`
# Will give me tty ID
MYTTY=`who -m | awk '{print $2;}' | cut -d '/' -f2`
DATE=`date +"%Y_%m_%d_%H%M%S"`
DAY=`date +"%Y_%m_%d"`
shopt -s histappend
mkdir -p $HOME/HISTORY/${WHOAMI}/${DAY}
printf "#`date '+%s'`\nll\n" > $HOME/HISTORY/${WHOAMI}/${DAY}/.HIST_${MYTTY}_${DATE}
export HISTTIMEFORMAT='%F %T '
export HISTFILESIZE=100
export HISTSIZE=100
# stores history file per terminal
export HISTFILE=$HOME/HISTORY/${WHOAMI}/${DAY}/.HIST_${MYTTY}_${DATE}
export PS1='[\[\e[4;32m\]\u@\h\[\e[0m\] \[\e[1;36m\]$PWD\[\e[0m\]]\! $'
# Updates the HISTFILE at real time i.e. when user presses enter
export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}"
history -r $HISTFILE
If I execute a command in my local terminal it works well and it gets saved in history.
What I have to do to get commands launched via SSH get saved in my local bash history?
Upvotes: 1
Views: 2346
Reputation: 9
Type bash into terminal when you log on and see if that fixes it.
If it does type echo $SHELL
and see what your default shell is.
If you are on Ubuntu server your going to see /bin/sh
type usermod --shell /bin/bash "username"
Verify by echo $SHELL and then grep "username" /etc/passwd Reload ssh with systemctl reload sshd and then systemctl restart sshd.
Now Reboot and you should have color and history.
Sometimes you have to edit .bashrc
file to force color on the line that's commented. And make sure that .profile
is referencing that on login which it should be by default..
Let me know if this works!
PS: if you at anytime typed sudo nano .bash_profile
or created a .bash_profile
type ls -la
in your home directory if you delete that and the follow the systemctl
reload reboot you should be good you don't want your .profile
to not be referenced.
Upvotes: 0