linux ssh 不保存操作记录history

来源:互联网 发布:float在c语言中的意思 编辑:程序博客网 时间:2024/06/06 03:29


转自http://blog.csdn.net/liushu_it/article/details/43835709

     Sanr” 博客,请务必保留此出处http://0x007.blog.51cto.com/6330498/1637909


————————————————

1)history -c  //是把Linux下的/root/.bash_history  全给清了,实现不保存,作为黑客是不地道的。
再从其他终端倒腾回去:
history |awk -F" "  '{if(NR>0){$1="";print $0}}'|grep -v "multepollserver" > /root/.bash_history

2)不留痕迹的办法,把指向给修改到/dev/null下:
[root@localhost ~]# echo $HISTFILE
/root/.bash_history
[root@localhost ~]# HISTFILE=/dev/null
[root@localhost ~]# echo $HISTFILE    
/dev/null

[root@test ~]# vi /root/.bash_history
对前面的:history |awk -F"  " '{print $3}' > /root/.bash_history 删除,退出即可。



请教一个关于linux下不保存命令历史记录的问题,不需要在任何文件中设置:
ssh 登陆之后,在命令行下运行
set HISTIGNORE=*
或者
export HISTIGNORE=*
以后的命令就不会被保存了。


最方便的命令

unset HISTORY HISTFILE HISTSAVE HISTZONE HISTORY HISTLOG; export HISTFILE=/dev/null; export HISTSIZE=0; export HISTFILESIZE=0



用 history -c 清空历史命令.
在.bashrc的最后行追加
unset HISTFILE
这样做终端历史记录还是保存到了.bash_history文件中,只是新打开的终端不能直接用上键调用而已,用"cat .bash_history"仍能查看历史记录
cat .bash_history 看到的历史记录是 unset HISTFILE 之前保留的命令.
unset HISTFILE 之后的命令并没有保留.
用 history -c 清空历史命令.


步骤如下:
1、建立一个文件来存储常用命令,例如/root/history.txt,把常用命令当成文本写进去,每个命令占一行
2、在终端运行history -c,清除杂乱的历史记录
3、运行history -r /root/history.txt,把命令读进来作为当前bash的历史记录
4、运行history,就得到一个整洁的命令列表了,例如:
[root@localhost windata]# history -c
[root@localhost windata]# history -r /root/history.txt
[root@localhost windata]# history
1 history -r /root/history.txt
2 mount -t msdos -o iocharset=gb2312 /dev/sda1 /mnt/usb
3 mount -t vfat -o iocharset-gb2312 /dev/hda5 /mnt/windata
4 umount /mnt/windata
5 mount -t vfat -o iocharset-gb2312 /dev/hda5 /mnt/windata
6 cd /mnt/windata
7 history
[root@localhost windata]#
5、以后命令乱了,重复1-4的步骤,又可以使命令很清晰了。


可以用history命令来查看。
其它的记录你在/var/log这个文件夹下去找吧。它记录了所有的记录。
实际上。history命令也是读的/var/log的东西

历史命令都在 .bash_history 文件中呀,每个用户的家目录中都有这个文件的,去看他们的历史命令吧 
在每个用户的家目录里,看文本命令很多,如: cat \ more \ less \ vi 等等这些命令都可以看某个用户的 .bash_history 文件。

例:# more ~user/.bash_history        看 user 用户的历史命令,但是你要访问的权限才行。
.bash_history在每个用户的$HOME下
在每个用户的home目录下的.bash_history

6.把一些命令给去掉回写回/root/.bash_history的方法:
view plainprint?
  1. history |awk -F" "  '{if(NR>0){$1="";print $0}}'|grep -v "multepollserver" > /root/.bash_history  
原创粉丝点击