News for hackers. Stuff that matters.
Re:Shell Productivity Tips and Tricks by jpxw on Saturday April 25, 2020 @03:41AM (#22976447)
> If you want to remove a sensitive command from your history, you can simply edit your $HISTFILE history file and remove it.

It’s already too late at this point. Anybody on your machine can read the commands you are running, for example with ps. You should instinctively avoid entering anything in plaintext into a terminal which you don’t want other people to see. Any command line tool worth its salt will provide alternative ways of passing secrets (using configuration files for example).

Re:Shell Productivity Tips and Tricks by rrmm on Saturday April 25, 2020 @08:22AM (#22977560)
The worst is when you expect a password prompt so you type the password and hit enter, but you mistyped the original command and you end up typing your password in plaintext onto the command line. oops.
Re:Shell Productivity Tips and Tricks by McKayDavis on Saturday April 25, 2020 @01:36PM (#22979708)
If you're using `bash`, A quick remedy for this is:

  unset HISTFILE
  exit
This prevents `bash` from updating the `~/.bash_history` file on exit with the command you don't want memorialized. (assuming you don't also have some hook that updates your history file after every command)
Re:Shell Productivity Tips and Tricks by fitzn on Saturday April 25, 2020 @10:54AM (#22978568)
I understand what you're saying but if anybody on your machine can read the commands, can't they also read your configuration files? Or are you saying a different user on the machine can run `ps` and see my processes but not necessarily my portion of the file system? My thought is if the file is not encrypted on the disk, then any desktop application can read it. So, while I agree that preventing a user from reading bash history is not worth it if they can read your processes, aren't configuration files (if unencrypted) just as insecure?
Re:Shell Productivity Tips and Tricks by mturmon on Saturday April 25, 2020 @12:40PM (#22979296)
In a Unix system, files have 3 levels of permissions — for the user who owns the file, the group-of-users that owns the file, and any system user.

So, a given config file can have permissions so that the file owner can read and write, but other users cannot. Like your ssh keys.

But ‘ps’ can be run by anyone, and it can typically access the whole command line you used.

Re:Shell Productivity Tips and Tricks by fitzn on Sunday April 26, 2020 @07:55PM (#22991454)
Ah, right. This makes a lot of sense. Thank you!
Re:Shell Productivity Tips and Tricks by gvjddbnvdrbv on Saturday April 25, 2020 @03:51PM (#22980868)
This is true but in a typical desktop usecase there is one user.
Re:Shell Productivity Tips and Tricks by perlgeek on Saturday April 25, 2020 @04:38PM (#22981249)
This doesn't have to be true. You can mount /proc with hidepid to prevent users from seeing other users' processes: https://access.redhat.com/documentation/en-us/red_hat_enterp...
Re:Shell Productivity Tips and Tricks by capableweb on Sunday April 26, 2020 @03:54AM (#22985396)
Indeed! One thing that at least works on zsh is to prefix the command with a space, then the command doesn't go into the history file.

So if you do `date`, it'll end up in the history file but if you do ` date` (one space prefixed), it won't. One `clear` later and it's like the command was never run.

Re:Shell Productivity Tips and Tricks by jlgaddis on Saturday April 25, 2020 @04:16PM (#22981078)
> Anybody on your machine can read the commands you are running, for example with ps.

This is why I always mount /proc with the "hidepid=2" option (as well as the "gid=<n>" option to ensure that doesn't apply to the members of a specific group, such as the "admins" of the box).

Re:Shell Productivity Tips and Tricks by tyingq on Saturday April 25, 2020 @08:08AM (#22977488)
Not a real solution, but you can assign new values to argv/argc to hide things from ps.

With Perl, for example, assign to $0.

$0="what /bin/ps will see";

Re:Shell Productivity Tips and Tricks by cassiet on Saturday April 25, 2020 @07:28AM (#22977336)
How exactly?
Re:Shell Productivity Tips and Tricks by jedimastert on Saturday April 25, 2020 @08:22AM (#22977558)
I think what OP meant was closer to "if it could have been entered into the bash history than there's other ways it could be seen".

Most CLI programs that need sensetive information as input should either do it interactively (a la sudo), as standard input, or configuration file. If worst comes to very worst, you can put the sensitive info in a text file and use backticks. For example:

  some-command --username=jedimastert --password=`cat secret.txt`
Re:Shell Productivity Tips and Tricks by fooblat on Saturday April 25, 2020 @12:28PM (#22979224)
> some-command --username=jedimastert --password=`cat secret.txt`

This will not work in the way that you suggest. The output of ps will show the result of `cat secret.txt` and thus reveal the password.

Re:Shell Productivity Tips and Tricks by jedimastert on Sunday April 26, 2020 @02:00PM (#22988840)
Would it? Poo. That's my bad.
Re:Shell Productivity Tips and Tricks by lmz on Saturday April 25, 2020 @08:46AM (#22977679)
How would backticks help with hiding it from ps?
Re:Shell Productivity Tips and Tricks by jedimastert on Sunday April 26, 2020 @02:00PM (#22988843)
I thought that's how it would show up in ps. Apparently I was incorrect. :(