8

I've installed the hashalot first to use the sha256.
Then something strange happened when using the command + filename:

mlockall: Cannot allocate memory
Warning: couldn't lock memory, are you root?
Enter passphrase:

I've never needed to enter passphrase before for this as far as I remember. And if I do provide a password or use sudo before running the command I get strange characters on result:

��z�9��E-�c���F�K��"�x~�(8�J��

I am on an OS based on Ubuntu (Elementary OS Freya).

Yaron
  • 724
  • 2
  • 7
  • 14
anon
  • 83
  • 1
  • 5

3 Answers3

5

Did you read the description of the package you installed?

This program will read a passphrase from standard input and print a binary (not printable) hash to standard output.

You tried to print the output to console; what you're seeing is expected behavior.

Darth Android
  • 37,872
  • 5
  • 94
  • 112
  • 2
    Well, I just found out that what I was exactly looking for is sha256sum! That's why the use of it in the past was different... And I am learning about Linux and even computing, so I don't really understand the purpose of sha256 only. But from now on I'll start reading as many man pages as possible! Your answer did help me dig further and get where I wanted :) Thanks a lot! – anon Jul 01 '16 at 17:02
  • Why would this be expected behavior? It prints that warning even using the `-x` switch to print the output as hex, which suggests that this answer is incorrect. I believe the better (closer to correct) answer is [Jeffrey Gong's](https://superuser.com/a/1202347). – Reinstate Monica -- notmaynard Mar 26 '21 at 18:31
4

ubuntu 16.04 default max shared memory per user is 64k. I upped it to 1gb for all users, error goes away.

by adding a line to the end of the /etc/security/limits.conf file will fix this. no need to reboot the system, you'll need to logout though.

$ echo test  | sha256 -s test | base64
mlockall: Cannot allocate memory
Warning: couldn't lock memory, are you root?
NyaDNd1pMQRb3N+SYj/4GaZCRLU9DnRtQ4eXNJ1NpXg=

$ ulimit -l
64
$ sudo bash
# echo "*   -     memlock   1048576" >> /etc/security/limits.conf

log out now.

$ ulimit -l
1048576

$ echo test  | sha256 -s test | base64
NyaDNd1pMQRb3N+SYj/4GaZCRLU9DnRtQ4eXNJ1NpXg=

no more tears!!

I'm guessing this warning is about the corner case of having your secrets paged out of memory, and someone finding it latter in tmp space.

0

I think you're looking for sha256 -x. From the man page: "If the -x option is given then the hash will be printed as a string of hexadecimal digits." (https://manpages.debian.org/jessie/hashalot/sha256.1.en.html)

miara
  • 101
  • 1