簡體   English   中英

通過 ssh 執行命令並且不會保存在 bash 歷史記錄中

[英]Executing a command via ssh and does not get saved in bash history

當我通過 SSH 從計算機執行命令到我的 Linux 服務器時,它不會保存在其 bash 歷史記錄中。

我的 my.bash_profile 設置如下:

[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

如果我在本地終端中執行命令,它會運行良好,並且會保存在歷史記錄中。

我必須做些什么才能讓通過 SSH 啟動的命令保存在我的本地 bash 歷史記錄中?

太感謝了。

真誠的,傑森

登錄時在終端中輸入 bash 並查看是否可以解決問題。

如果確實鍵入echo $SHELL並查看您的默認 shell 是什么。

如果您在 Ubuntu 服務器上,您將看到/bin/sh type usermod --shell /bin/bash "username"

通過 echo $SHELL 然后 grep "username" /etc/passwd 使用 systemctl reload sshd 然后 systemctl restart sshd 重新加載 ssh 進行驗證。

現在重新啟動,你應該有顏色和歷史。

有時您必須編輯.bashrc文件以在已注釋的行上強制使用顏色。 並確保.profile在登錄時引用它應該是默認的..

讓我知道這個是否奏效!

PS:如果您在任何時候鍵入sudo nano.bash_profile或在您的主目錄中創建.bash_profile類型ls -la如果您刪除它並按照systemctl reload reboot 您應該很好,您不希望您的.profile不是參考。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM