我一直在学习如何使用paramiko
包,结果发现我所有的密码都是明文存储在IPython的%hist
中。这不太好。
因此,我需要摆脱%hist
中特定部分的内容。话虽如此,我并不想清空整个历史记录。只需删除我不小心输入password =
或类似选定术语的部分即可。
谢谢
我不需要的评论:
%clear
仅清除会话,而不会清除历史记录。- 是的。我以后只会使用xSA_keys。
我一直在学习如何使用paramiko
包,结果发现我所有的密码都是明文存储在IPython的%hist
中。这不太好。
因此,我需要摆脱%hist
中特定部分的内容。话虽如此,我并不想清空整个历史记录。只需删除我不小心输入password =
或类似选定术语的部分即可。
谢谢
我不需要的评论:
%clear
仅清除会话,而不会清除历史记录。默认情况下,历史记录存储在$(ipython locate)/profile_default/history.sqlite
中。您可以删除该文件或对其进行任何操作(安全擦除等)。它是一个sqlite文件,因此您可以使用任何sqlite程序加载它并对其进行查询。
请检查$(ipython locate)/profile_default/
和其他$(ipython locate)/profile_xxx
,确保您没有任何其他历史记录文件。$(ipython locate)
通常为~/.ipython/
,但可能会有所不同:
ls $(ipython locate)/profile_*/*.sqlite
$(ipython locate)
给了我[TerminalIPythonApp] File not found: u'locate'
这个错误,但我可以在~/.ipython/profile_default/history.sqlite.
找到它。 - mlissner一个解决方案是:
sqlite ~/.ipython/profile_default/history.sqlite
delete from history where source like '%password =%';
~/.sqlite_history
中的sqlite3历史记录。 - Matthew D. Scholefieldsqlite ~/.ipython/profile_default/history.sqlite
sqlite3
而不是sqlite
。select * from history;
# session is the first column in history
delete from history where session=XXX;
select session from history order by -session limit 1;
结合@Ovidiu Ghinet的答案和@Matt的被接受的答案:
sqlite $(ipython locate)/profile_*/*.sqlite || sqlite3 $(ipython locate)/profile_*/*.sqlite
然后在sqlite控制台中执行以下命令:
delete from history where source like '%password%';
select * from history; /* confirm that no passwords left */
.quit /* forgot how to exit sqlite console? ;) */
%clear out #它会清除输出历史记录
顺便说一下,你也可以通过 %clear in 清除输入历史记录。
/home/user/.ipython/profile_default/history.sqlite