IPython: How to wipe IPython's history selectively & securely?

后端 未结 6 1196
北海茫月
北海茫月 2020-12-29 02:52

I have been learning how to use the paramiko package only to discover that all I stored passwords in plain text in IPython\'s %hist. Not so good.

相关标签:
6条回答
  • 2020-12-29 03:01

    History is store on $(ipython locate)/profile_default/history.sqlite by default. You can remove the file, and or do any operation you want on it (secure erase, etc..). It's an sqlite file so you can load it with any sqlite program and do query on it.

    Check in $(ipython locate)/profile_default/ and other $(ipython locate)/profile_xxx that you do not have any other history files. $(ipython locate) is usually ~/.ipython/ but can vary:

    ls $(ipython locate)/profile_*/*.sqlite
    
    0 讨论(0)
  • 2020-12-29 03:02

    Combining @Ovidiu Ghinet's answer with @Matt's accepted answer:

    sqlite $(ipython locate)/profile_*/*.sqlite || sqlite3 $(ipython locate)/profile_*/*.sqlite
    

    Then from within sqlite console:

    delete from history where source like '%password%';
    select * from history; /* confirm that no passwords left        */
    .quit                  /* forgot how to exit sqlite console? ;) */
    
    0 讨论(0)
  • 2020-12-29 03:05

    If you want completely from beginning, Just go and delete the following file manually(It worked for me)

    /home/user/.ipython/profile_default/history.sqlite

    0 讨论(0)
  • 2020-12-29 03:12

    I couldn't find the way to wipe IPython's history selectively, but I found out how to wipe data by built-in func, non-sqlite way:

    %clear out #it clears output history

    by the way, you can also clear in history by %clear in

    0 讨论(0)
  • 2020-12-29 03:20

    If you want to delete history from a particular session, run:

    sqlite ~/.ipython/profile_default/history.sqlite
    

    Note that on some systems, you will need to run sqlite3 rather than sqlite.

    Inside SQLite:

    select * from history;
    # session is the first column in history
    delete from history where session=XXX;
    

    Also, here is a SQLite query that will give you the id of your last session:

    select session from history order by -session limit 1;
    
    0 讨论(0)
  • 2020-12-29 03:24

    One solution would be:

    sqlite ~/.ipython/profile_default/history.sqlite
    
    delete from history where source like '%password =%';
    
    0 讨论(0)
提交回复
热议问题