date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,350,499,117,000
What command can be used to determine the used encryption on a LUKS partition (all the relevant information, initialization vector, generation scheme, mode of operation and block cipher primitive)?
If the decrypted volume is /dev/mapper/crypto then you can get the information with dmsetup table crypto 0 104853504 crypt aes-cbc-essiv:sha256 000[...]000 0 254:2 4096 If the encrypted volume is /dev/storage2/crypto then you get the information with cryptsetup luksDump /dev/storage2/crypto LUKS header information for /dev/storage2/crypto Version: 1 Cipher name: aes Cipher mode: cbc-essiv:sha256 Hash spec: sha256 [...]
How to determine what encryption is being used a LUKS partition?
1,350,499,117,000
I wanted to know why, before encrypting and installing itself on the drive , Kali : wiped the whole drive filled the drive with 0s filled the drive with 1s filled the drive with Random data wiped the drive again I know that Kali isn't meant to be installed, but that's not the point here. So, how is this useful before installing, say on a brand new HDD? I'm used to see that on HDD removal, not install.
There is no point in doing multiple passes. Once is enough. Filling a to-be-encrypted drive with random data mainly has two uses: get rid of old, unencrypted data make free space indistuingishable from encrypted data Usually if you encrypt you don't want anyone to see your data. So chances are, if you had old, unencrypted data on this drive, you want to get rid of it too. An SSD might take care of it easier and faster with blkdiscard. In fact, Linux mkfs TRIMs all data without even asking you for confirmation, which makes any kind of data recovery impossible. There is too much TRIM in Linux. Free space is a bit of a grey area. If you don't pre-fill with random data, on a brand new HDD, sectors that were never written to will be zeroes. On a SSD, if you allow discard/TRIM, free space will also be zero. While this does not affect your data in any way (it's still encrypted), it reveals how much free space/actual data you have, and where this free space/data is located. For example a hexdump -C of an encrypted, trimmed SSD will look somewhat like this: # hexdump -C /dev/ssd | grep -C 2 '^\*' ... -- b3eabff0 dc c9 c7 89 16 ca d3 4f a3 27 d6 df a0 10 c3 4f |.......O.'.....O| b3eac000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * b3f70000 5a 99 44 b5 9c 6b 1e 9c 81 cf 9a 43 b6 23 e9 0f |Z.D..k.....C.#..| b3f70010 2c e6 9a 5d 59 9b 46 5f 21 3f 4d 5f 44 5b 0a 6b |,..]Y.F_!?M_D[.k| -- b3f70ff0 5f 63 8d e8 c4 10 fd b1 a6 17 b5 7d 4a 57 09 68 |_c.........}JW.h| b3f71000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * b3f72000 5d 1c 09 dd c9 6b 57 18 db 67 e1 35 81 57 45 8e |]....kW..g.5.WE.| b3f72010 0f a8 be 39 ae e5 5f cf cf e3 8b a7 c1 25 1a a3 |...9.._......%..| -- ... From this you can tell I have free space segments at address 0xb3eac000 .. 0xb3f70000, b3f71000 .. b3f72000, ... and the inverse of that is of course data segments like 0xb3f70000 .. b3f71000. What can you do with it? Well, nothing(*). (*) is what I'd like to say. But people get creative. Free space patterns can be used to derive the type of filesystem you use (due to how/where they store metadata - if there is free space where ext4 would store one of its metadata backups, it's very likely not ext4, etc.). Sometimes it even reveals which distribution you use (if your Linux installer fills the filesystem deterministically, files might always end up at the same physical addresses). At that point someone might know where a specific system file is located and could modify/damage it in some way. (Installers should randomize the way they populate filesystems to prevent this.) However such considerations are very theoretical, and very low risk compared to how vulnerable most encrypted installations are due to other reasons. In most out of the box installs, it's more likely / simpler to just tamper with the initramfs, or install a keylogger, or exploit the running system, than somehow get raw access to and analyze encrypted data and hope to achieve anything this way. You should worry about these first before worrying about revealing free space. With SSD, it's completely normal to enable TRIM and thus have free space revealed at all times. This is also the case for encryption solutions that work on a file layer rather than block layer. With HDD, you mainly do the random wipe even on a new disk because you can, and there is no reason not to as it involves no cost (aside from a first-time setup) and no downsides.
Pre-encryption wipe, why?
1,350,499,117,000
I have generated RSA private key using below command: openssl genrsa -out privkey.pem 2048 And created a self signed certificate using below command: openssl req -new -x509 -key privkey.pem -out cacert.pem -days 3650 Now I am trying to convert cacert .pem file to certificate .cer Any ideas?
You can use the following command: openssl x509 -inform PEM -in cacert.pem -outform DER -out certificate.cer
Obtain .cer file from .pem file
1,350,499,117,000
I am in progress of resizing a LUKS encrypted partition that contains a single ext4 filesystem (no LVM or something). The cryptsetup FAQ recommends to remove the old partition and recreate it, but that sounds like wasting a lot time. Therefore I want to proceeed by manually, carefully resizing the partition. So far, I think that I need to do: Create an (encrypted) backup of the filesystem. Important! You won't be the first to lose your data while performing the following tasks. Unmount the existing ext4 filesystem (e.g. by booting into a Live CD). If booting from a Live CD, mount the encrypted partition using cryptsetup luksOpen /dev/sdXY ExistingExt4 Resize the existing ext4 filesystem. cryptsetup resize /dev/mapper/ExistingExt4 -b $SECTORS Close/ "unmount" the LUKS partition using cryptsetup luksClose ExistingExt4 Shrink the partition size. Are the above steps correct? In step 4, what should I choose for $SECTORS? Is this step even necessary? The cryptsetup manual page is not really descriptive on the resize option: resize <name> resizes an active mapping <name>. If --size (in sectors) is not specified, the size of the underlying block device is used. Finally, if I shrink the ext4 partition by 15 GiB, can I safely assume that 15 GiB can be removed from the existing partition using parted? If yes, how to do so? My disk is GPT partitioned, if that matters.
After backing up (step 1) and unmounting (between 2 and 3), run fsck to ensure that the filesystem is healthy: e2fsck -f /dev/mapper/ExistingExt4 Other than that, the steps are OK. Purpose of the cryptsetup resize command what should I choose for $SECTORS? Is this step even necessary? This step is necessary, otherwise the partition would still show up at the old side. This is confirmed with Nautilus, even after resizing with resize2fs, the LUKS partition showed up as the old size. After running cryptsetup resize, the correct number is shown. This step is not necessary. It only affects the current size status as shown in the file browser. After changing the size and closing/opening the partition again, the number is restored. So, when closing the LUKS partition as shown later will make this obsolete. $SECTORS can be determined by looking at the output of cryptsetup status ExistingExt4: /dev/mapper/ExistingExt4 is active. type: LUKS1 cipher: aes-cbc-essiv:sha256 keysize: 256 bits device: /dev/sda2 sector size: 512 offset: 2056 sectors size: 156049348 sectors mode: read/write (As of cryptsetup 2.0.0 (December 2017), the sector size may be larger than 512 bytes: see the cryptsetup(8) manpage and the --sector-size option.) Thus, to subtract 15 GiB, use a sector size of 156049348 - 15 * 1024 * 1024 * 2 = 124592068: cryptsetup resize ExistingExt4 -b 124592068 Resizing the partition with parted As for resizing the partition, parted works fine with GPT partitions. The resize command does not work however, as a workaround (or solution), remove the partition information and create a new partition as inspired by http://ubuntuforums.org/showthread.php?p=8721017#post8721017: # cryptsetup luksClose ExistingExt4 # parted /dev/sda2 GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) unit s (parted) p Model: ATA INTEL SSDSA2CW08 (scsi) Disk /dev/sda: 156301488s Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 34s 2082s 2049s Boot bios_grub 3 2083s 250034s 247952s ext2 RootBoot 2 250035s 156301438s 156051404s Everything As 15 GiB has to be shaved off, the new end becomes 156301438 - 15 * 1024 * 1024 * 2 = 124844158. Since I want to change partition 2, I first have to remove it and then recreate it with the label "Everything" (this could be changed if you like). Note: this disk has a GPT layout. For MBR, you should replace Everything by primary or extended (untested, resizing a partition on MBR has not been tested and is not recommended because it is untested). WARNING: the following commands has destroyed data. Do not copy it without understanding what is happening. The sector dimensions must be changed, otherwise you WILL destroy your partition(s). I am in no way responsible for your stupidness, BACKUP BACKUP BACKUP your data to a second storage medium before risking your data. (parted) rm 2 (parted) mkpart Everything 250035s 124844158s Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? ignore (parted) p Model: ATA INTEL SSDSA2CW08 (scsi) Disk /dev/sda: 156301488s Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 34s 2082s 2049s Boot bios_grub 3 2083s 250034s 247952s ext2 RootBoot 2 250035s 124844158s 124594124s Everything (parted) quit In the above parted example, my sectors are not aligned which is a mistake from an earlier installation, do not pay too much attention to it. That is it! You can use cryptsetup status and file -Ls /dev/... to verify that everything is OK and then reboot.
How can I shrink a LUKS partition, what does `cryptsetup resize` do?
1,350,499,117,000
Suppose I want to encrypt a file so that only I can read it, by knowing my SSH private key password. I am sharing a repo where I want to encrypt or obfuscate sensitive information. By that, I mean that the repo will contain the information but I will open it only in special cases. Suppose I am using SSH-agent, is there some easy way to encrypt the file for only me to open it later? I cannot see why I should use GPG for this, question here; basically I know the password and I want to only decrypt the file by the same password as my SSH key. Is this possible?
I think your requirement is valid, but on the other hand it is also difficult, because you are mixing symmetric and asymmetric encryption. Please correct me if I'm wrong. Reasoning: The passphrase for your private key is to protect your private key and nothing else. This leads to the following situation: You want to use your private key to encrypt something that only you can decrypt. Your private key isn't intended for that, your public key is there to do that. Whatever you encrypt with your private key can be decrypted by your public key (signing), that's certainly not what you want. (Whatever gets encrypted by your public key can only be decrypted by your private key.) So you need to use your public key to encrypt your data, but for that, you don't need your private key passphrase for that. Only if you want to decrypt it you would need your private key and the passphrase. Conclusion: Basically you want to re-use your passphrase for symmetric encryption. The only program you would want to give your passphrase is ssh-agent and this program does not do encryption/decryption only with the passphrase. The passphrase is only there to unlock your private key and then forgotten. Recommendation: Use openssl enc or gpg -e --symmetric with passphrase-protected keyfiles for encryption. If you need to share the information, you can use the public key infrastucture of both programs to create a PKI/Web of Trust. With openssl, something like this: $ openssl enc -aes-256-ctr -in my.pdf -out mydata.enc and decryption something like $ openssl enc -aes-256-ctr -d -in mydata.enc -out mydecrypted.pdf Update: It is important to note that the above openssl commands do NOT prevent the data from being tampered with. A simple bit flip in the enc file will result in corrupted decrypted data as well. The above commands cannot detected this, you need to check this for instance with a good checksum like SHA-256. There are cryptographic ways to do this in an integrated way, this is called a HMAC (Hash-based Message Authentication Code).
Encrypting file only with SSH -priv-key?
1,350,499,117,000
I would like to download some files from my server into my laptop, and the thing is that I want this communication to be as stealth and secure as it can be. So, far I came up using VPN, in that way I redirect the whole internet traffic of my laptop via my server. Additionally, I tried to send a file using ftp and observing Wireshark at the same time. The communication seems to be encrypted, however I would like also to encrypt the file itself (as a 2nd step security or something like that). My server is a RasPi running Raspbian. My laptop is Macbook Air. I want firstly to encrypt a file in my Ras Pi and secondly download it. How can I do that?
You can use openssl to encrypt and decrypt using key based symmetric ciphers. For example: openssl enc -in foo.bar \ -aes-256-cbc \ -pass stdin > foo.bar.enc This encrypts foo.bar to foo.bar.enc (you can use the -out switch to specify the output file, instead of redirecting stdout as above) using a 256 bit AES cipher in CBC mode. There are various other ciphers available (see man enc). The command will then wait for you to enter a password and use that to generate an appropriate key. You can see the key with -p or use your own in place of a password with -K (actually it is slightly more complicated than that since an initialization vector or source is needed, see man enc again). If you use a password, you can use the same password to decrypt, you do not need to look at or keep the generated key. To decrypt this: openssl enc -in foo.bar.enc \ -d -aes-256-cbc \ -pass stdin > foo.bar Notice the -d. See also man openssl.
How can I encrypt a file?
1,350,499,117,000
I'm trying to set up OfflineIMAP to authenticate via a gpg encrypted file (that way I can consolidate all my encryption to my gpg-agent process). From the documentation, it seems the only way to encrypt one's server passwords is to use gnome-keyring (which I'd prefer not to run on my headless server). Is there a way to pipe in my password from a gpg file the way you can with mutt? I know you can add extra features to offlineimap with the extension python file, but I'm afraid I wouldn't know where to start with that.
Another method of leaving offlineimap running with knowledge of your password, but without putting the password on disk, is to leave offlineimap running in tmux/screen with the autorefresh setting enabled in your ~/.offlineimaprc You need to add autorefresh = 10 to the [Account X] section of the offlineimaprc file, to get it to check every 10 minutes. Also delete any config line with password or passwordeval. Then run offlineimap - it will ask for your password and cache it in memory. It will not exit after the first run, but will sleep for 10 minutes. Then it will wake up and run again, but it will still remember your password. So you can leave a tmux session running with offlineimap, enter your password once, and offlineimap will be fine there after.
Encrypt OfflineIMAP Password
1,350,499,117,000
I have destroyed my Mint Linux installation. I just wanted access to my remote storefront. So what happened was I was having trouble with ICEauthority file in my home directory. So following different directions on the internet I came to the conclusion that I could set the home directory recursively to chmod 755 to allow that file to work…eventually I ran into problems with the system loading. Eventually by setting the home directory to executable permission for root was I able to get read/write access…but then i reset my machine oh why oh why did i reset my machine!!! - now the system throws me the same error with ICEauthority but it never gets me into the OS because the disk is encrypted. Nothing I’ve tried seems to work and I don’t have the original mounting seed. I’ve also tried sudo ecryptfs-recover-private but my system then just says No such file or directory: frankenmint@honeybadger /home $ sudo ecryptfs-recover-private INFO: Searching for encrypted private directories (this might take a while)... INFO: Found [/home/.ecryptfs/frankenmint/.Private]. Try to recover this directory? [Y/n]: y INFO: Found your wrapped-passphrase Do you know your LOGIN passphrase? [Y/n] y INFO: Enter your LOGIN passphrase... Passphrase: Inserted auth tok with sig [979c6cdf80d2e44d] into the user session keyring mount: No such file or directory ERROR: Failed to mount private data at [/tmp/ecryptfs.Hy3BV96c]. I’m really worried because I had important files on there that were stored on a virtual machine…If I could just get to those files then I would have no qualms nuking the setup and starting over
I found that running sudo bash and then running ecryptfs-recover-private as root (rather than via sudo) worked. Not sure why it should be any different. Edit: TL;DR: # ecryptfs-unwrap-passphrase /mnt/crypt/.ecryptfs/user/.ecryptfs/wrapped-passphrase - | ecryptfs-add-passphrase --fnek - < Type your login password here > Inserted auth tok with sig [aaaaaaaaaaaaaaaa] into the user session keyring Inserted auth tok with sig [bbbbbbbbbbbbbbbb] into the user session keyring You will not see a prompt and must type your login password, blind, into the above command. Replace the aaaaaaaaaaaaaaaa and bbbbbbbbbbbbbbbb below with the hex signatures between brackets from the output above, in order: # mount -i -t ecryptfs -o ecryptfs_sig=aaaaaaaaaaaaaaaa,ecryptfs_fnek_sig=bbbbbbbbbbbbbbbb,ecryptfs_cipher=aes,ecryptfs_key_bytes=16 /mnt/crypt/.ecryptfs/user/.Private /mnt/plain Preliminaries It turns out just running as root did not work reliably for me; sometimes it did, sometimes it didn't. Basically, ecryptfs seems buggy and quite user-unfriendly, often confusing login passwords and mount passphrases. After going down a deep, dark rabbit hole, I have some tips that should help. These notes are for Ubuntu 17.10, ecryptfs-utils 111-0, and you should become root before starting. I assume you want to mount your home directory from /mnt/crypt (which should already be mounted) to /mnt/plain, and you should replace user with the username. Start Easy The first thing to try is: # ecryptfs-recover-private /mnt/crypt/.ecryptfs/user/.Private If this works, well, you're lucky. If not, it may give an error message from mount about no such file or directory. This is extremely misleading: what it really means is your mount passphrase is wrong or missing. Get The Signatures Here is the important part: we need to verify ecryptfs is really trying the right mount passphrase(s). The passphrases must be loaded into the Linux kernel before ecryptfs can mount your filesystem. ecryptfs asks the kernel for them by their signature. The signature is a 16-byte hex value (and is not cryptographically sensitive). You can find the passphrase signatures ecryptfs is expecting: # cat /mnt/crypt/.ecryptfs/user/.ecryptfs/Private.sig aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbb Remember these. The goal is to get passphrases with these signatures loaded into the kernel and then tell ecryptfs to use them. The first signature (aaaaaaaaaaaaaaaa) is for the data, and the second (bbbbbbbbbbbbbbbb) is the FileName Encryption Key (FNEK). Get the mount passphrase This command will ask you for you login password (with a misleading prompt), and output your mount passphrase: # ecryptfs-unwrap-passphrase /mnt/crypt/.ecryptfs/user/.ecryptfs/wrapped-passphrase Copy this but be careful!!, as this is extremely cryptographically sensitive, the keys to the kingdom. Try an interactive mount The next thing to try is: # mount -t ecryptfs /mnt/crypt/.ecryptfs/user/.Private /mnt/plain The crucial thing here is that mount needs your (super-sensitive) mount passphrase that we just copied (not your login password). This will ask you some questions, and you can accept the defaults except say yes to Enable filename encryption. It may give you a warning and ask to cache the signatures; you can say yes to both, but do double-check that you've got the right mount passphrase. You will see the options that mount has decided to try for you: Attempting to mount with the following options: ecryptfs_unlink_sigs ecryptfs_fnek_sig=bbbbbbbbbbbbbbbb ecryptfs_key_bytes=16 ecryptfs_cipher=aes ecryptfs_sig=aaaaaaaaaaaaaaaa Mounted eCryptfs If the signatures are wrong (don't match what you got from Private.sig), the mount won't work. ...but it will very unhelpfully report that it did. You will have to do an ls /mnt/plain and cat a file to make sure. At this point you can also look in /var/log/syslog and verify that ecryptfs is looking for the same signatures we are. There are clearly two serious issues with ecryptfs here, and we have to work around them. Load the keys into the kernel If the interactive mount didn't help, we have to load the keys into the kernel ourselves and manually specify them in the mount options. # ecryptfs-add-passphrase --fnek And paste in your (super-senstive) mount passphrase copied from above. This should output: Inserted auth tok with sig [aaaaaaaaaaaaaaaa] into the user session keyring Inserted auth tok with sig [bbbbbbbbbbbbbbbb] into the user session keyring Mount manually Now the passphrases are loaded into the kernel, and we just need to tell mount to use them: # umount /mnt/plain # mount -i -t ecryptfs -o ecryptfs_sig=aaaaaaaaaaaaaaaa,ecryptfs_fnek_sig=bbbbbbbbbbbbbbbb,ecryptfs_cipher=aes,ecryptfs_key_bytes=16 /mnt/crypt/.ecryptfs/user/.Private /mnt/plain You'll notice the options are similar to what the interactive mount printed out, except we're manually telling ecryptfs what's up. Hopefully this works. If not, you can check that the keys are loaded into the kernel with the correct signatures using keyctl list @u, which should print out at least the two signatures you're expecting.
mount: No such file or directory with encrypted recovery
1,350,499,117,000
I want to know the type of symmetric encryption (after authentication) used by ssh in a connection client-server. I'm not sure who determines the encryption. Client or Server?. I have looked in /etc/ssh/ssh_config (on client) and /etc/ssh/sshd_config (on server) and nothing.
Both ssh_config (client configuration) and sshd_config (server configuration) have a Ciphers option that determine the supported ciphers. If the option doesn't appear in the configuration file, a built-in default applies. It is mentioned in the manual page for your version (unless your distribution tweaked the list at compile time without updated the man page). The actual cipher for a given connection is determined according to RFC 4253: The chosen encryption algorithm to each direction MUST be the first algorithm on the client's name-list that is also on the server's name-list. You can see what both parties had to offer and which cipher was chosen for a given connection by running ssh -vv.
how to know the type of symmetric encryption used by ssh?
1,350,499,117,000
Is there a preferred method to set up full-disk encryption under OpenBSD, similar to dm-crypt under Linux? I'm looking for full-disk encryption, as if someone were to steal my notebook they could potentially access the data stored on it. Another reason is that I'm not always next to my notebook, so someone could potentially compromise the integrity of my netbook. These are the two major issues which make me believe that full-disk encryption is important for me.
OpenBSD supports full-disk encryption only since OpenBSD 5.3. Earlier versions require a cleartext boot partition. I don't know when the installer was modified to support direct installation to an encrypted partition (with the bootloader still unencrypted of course, because something has to decrypt the next bit). There's little use in encrypting the system partition anyway¹. So I suggest installing the system normally, then creating an encrypted filesystem image and putting your sensitive data (/home, parts of /var, perhaps a few files in /etc) there. If you want to encrypt the system partition anyway (because you have some special use case, like some confidential software), and you didn't install an encrypted system originally, here's how you can do it. Boot into your OpenBSD installation and create a file that will contain the encrypted filesystem image. Make sure to choose a reasonable size since it'll be hard to change later (you can create an additional image, but you'll have to enter the passphrase separately for each image). The vnconfig man page has examples (though they're missing a few steps). In a nutshell: dd if=/dev/urandom of=/ENCRYPTED.img bs=1m count=4096 vnconfig -k svnd0 /ENCRYPTED.img # type your passphrase { echo a a; echo w; echo q; } | disklabel -E /svnd0 # create a single slice newfs /dev/svnd0a mount /dev/svnd0a /mnt mv /home/* /mnt umount /mnt umount /dev/svnd0c Add corresponding entries to /etc/fstab: /ENCRYPTED.img /dev/svnd0c vnd rw,noauto,-k /dev/svnd0a /home ffs rw,noauto Add commands to mount the encrypted volume and the filesystem in it at boot time to /etc/rc.local: echo "Mounting encrypted volumes:" mount /dev/svnd0c fsck -p /dev/svnd0a mount /home Check that everything is working correctly by running these commands (mount /dev/svnd0c && mount /home). Note that rc.local is executed late in the boot process, so you can't put files used by the standard services such as ssh or sendmail on the encrypted volume. If you want to do that, put these commands in /etc/rc instead, just after mount -a. Then move the parts of your filesystem you consider to be sensitive and move them to the /home volume. mkdir /home/etc /home/var mv /etc/ssh /home/etc ln -s ../home/etc/ssh /home/etc mv /var/mail /var/spool /home/var ln -s ../home/var/mail ../home/var/spool /var You should encrypt your swap as well, but OpenBSD does that automatically nowadays. The newer way to get an encrypted filesystem is through the software raid driver softraid. See the softraid and bioctl man pages or Lykle de Vries's OpenBSD encrypted NAS HOWTO for more information. Recent versions of OpenBSD support booting from a softraid volume and installing to a softraid volume by dropping to a shell during the installation to create the volume. ¹ As far as I can tell, OpenBSD's volume encryption is protected for confidentiality (with Blowfish), not for integrity. Protecting the OS's integrity is important, but there's no need for confidentiality. There are ways to protect the OS's integrity as well, but they are beyond the scope of this answer.
How should one set up full-disk encryption on OpenBSD?
1,350,499,117,000
I've read about how to make hard drives secure for encryption, and one of the steps is to write random bits to the drive, in order to make the encrypted data indistinguishable from the rest of the data on the hard drive. However, when I tried using dd if=/dev/urandom of=/dev/sda in the past, the ETA was looking to be on the order of days. I saw something about using badblocks in lieu of urandom, but that didn't seem to help a whole lot. I would just like to know if there are any ways that might help me speed this up, such as options for dd or something else I may be missing, or if the speed is just a limitation of the HD.
dd if=/dev/urandom of=/dev/sda, or simply cat /dev/urandom >/dev/sda, isn't the fastest way to fill a disk with random data. Linux's /dev/urandom isn't the fastest cryptographic RNG around. Is there an alternative to /dev/urandom? has some suggestions. In particular, OpenSSL contains a faster cryptographic PRNG: openssl rand $(</proc/partitions awk '$4=="sda" {print $3*1024}') >/dev/sda Note that in the end, whether there is an improvement or not depends on which part is the bottleneck: the CPU or the disk. The good news is that filling the disk with random data is mostly useless. First, to dispel a common myth, wiping with zeroes is just as good on today's hardware. With 1980s hard disk technology, overwriting a hard disk with zeroes left a small residual charge which could be recovered with somewhat expensive hardware; multiple passes of overwrite with random data (the “Gutmann wipe”) were necessary. Today even a single pass of overwriting with zeroes leaves data that cannot realistically be recovered even in laboratory conditions. When you're encrypting a partition, filling the disk with random data is not necessary for the confidentiality of the encrypted data. It is only useful if you need to make space used by encrypted data indistinguishable from unused space. Building an encrypted volume on top of a non-randomized container reveals which disk blocks have ever been used by the encrypted volume. This gives a good hint as to the maximum size of the filesystem (though as time goes by it will become a worse and worse approximation), and little more.
Fast Way to Randomize HD?
1,350,499,117,000
I have a fairly standard disk encryption setup in Debian 5.0.5: unencrypted /boot partition, and encrypted sdaX_crypt that contains all other partitions. Now, this is a headless server installation and I want to be able to boot it without a keyboard (right now I can boot it only with a keyboard and a monitor attached). So far I have an idea of moving /boot partition to an USB drive and make slight modifications to auto-enter the key (I think there is just a call to askpass in the boot script somewhere). This way I can boot headless, just need to have a flash drive in at boot time. As I see it, the problem with it is that I need to invest time into figuring out all bits and pieces to make it work, If there is an update, which regenerates initrd, I need to regenerate the boot partition on the USB, which seems tedious. The question: is there a standard low-upkeep solution available for what I want to do? Or should I be looking elsewhere altogether?
You can setup your system to require a key instead of a password and change some scripts to search for this key on a USB stick. I found a detailed explanation for this process on Debian Lenny. There are some notes in the end that describe necessary changes for newer versions of Debian.
Full disk encryption with password-less authentication in Linux
1,350,499,117,000
I've created a user ... but forgotten the password mysql> create user 'blayo'@'%' identified by 'right'; Which Linux command line tool can encrypt the password the same way mysql 5.5 does ? mysql> select Password,User from mysql.user ------------------------------------------+-------+ *920018161824B14A1067A69626595E68CB8284CB | blayo | ...to be sure I use the right one $ tool right *920018161824B14A1067A69626595E68CB8284CB
Well, the trivial (perhaps cheating) way would be to run: mysql -NBe "select password('right')" This will produce a password using whatever password hashing scheme your version of mysql uses. [EDIT: added -NB, which gets rid of the column names and ascii table art.]
Encrypt a password the same way mysql does
1,350,499,117,000
2017 WARNING! The accepted answer appears to work, but with recent kernels I discovered that the system would hang as soon as it started swapping. If you attempt using an encrypted swap file, make sure that it actually swaps properly. It took me a long time to figure out why my system kept locking up for no apparent reason. I've gone back to using an encrypted swap partition, which does work correctly. How do I set up an encrypted swap file (not partition) in Linux? Is it even possible? All the guides I've found talk about encrypted swap partitions, but I don't have a swap partition, and I'd rather not have to repartition my disk. I don't need suspend-to-disk support, so I'd like to use a random key on each boot. I'm already using a TrueCrypt file-hosted volume for my data, but I don't want to put my swap in that volume. I'm not set on using TrueCrypt for the swap file if there's a better solution. I'm using Arch Linux with the default kernel, if that matters.
Indeed, the page describes setting up a partition, but it's similar for a swapfile: dd if=/dev/urandom of=swapfile.crypt bs=1M count=64 loop=$(losetup -f) losetup ${loop} swapfile.crypt cryptsetup open --type plain --key-file /dev/urandom ${loop} swapfile mkswap /dev/mapper/swapfile swapon /dev/mapper/swapfile The result: # swapon -s Filename Type Size Used Priority /dev/mapper/swap0 partition 4000176 0 -1 /dev/mapper/swap1 partition 2000084 0 -2 /dev/mapper/swapfile partition 65528 0 -3 swap0 and swap1 are real partitions.
How do I set up an encrypted swap file in Linux?
1,350,499,117,000
I recently installed Fedora 20. I don't recall what exact options I chose for encrypting the disk/LVM during installation. It installed fine and I can log in etc. Here is the situation I have: I booted up with LiveCD and tried the following: (I have installed Fedora20 to /dev/sda3' partition). If I run cryptsetup open /dev/sda3 fedo I get an error saying it is not a LUKS device. I I run cryptsetup luksDump /dev/sda3 I get an error saying it is not a LUKS device If I run cryptsetup open --type plain /dev/sda3 fedo, it prompts for password and it opens the device fine. So, obviously, that is a plain-text encrypted (without LUKS header) partition. Now, when I try to run mount /dev/mapper/fedo /mnt/fedora, it says unknown crypto_LUKS filesystem. I do have LVM on top of it, so, I can run pvdisplay, vgdisplay, lvdisplay and it shows information. I have a VG called fedora and two LVs, viz 00 for swap partition and 01 for / partition. Now, if I do a cryptsetup luksDump /dev/fedora/01 I can see LUKS headers etc. And, I can mount by running mount /dev/fedora/00 /mnt/fedora, no password prompt. So, do I have a LUKS-over-LVM-over-(plain-text)-encrypted partition? Here is my output of lsblk: # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 37.3G 0 disk |-sda3 8:3 0 17.4G 0 part |-fedora-00 253:0 0 2.5G 0 lvm | |-luks-XXXXX 253:3 0 2.5G 0 crypt [SWAP] |-fedora-01 253:1 0 15G 0 lvm |-luks-XXXXX 253:2 0 15G 0 crypt / So, the question is, how to figure out whether I have LVM-over-LUKS or LUKS-over-LVM, or some other combination thereof (LUKS over LVM over LUKS etc)? To make my question clear, I know I have LVM and LUKS, I want to figure out the order of them.
cryptsetup luksDump /dev/fedora/01 shows the LVM logical volume to be a LUKS encrypted volume. The output of pvs or pvdisplay would show the partition /dev/sda3 to be a physical volume. Thus you have LUKS over LVM. At a lower level, you have LVM over PC partition. The output of lsblk confirms this: sda is a disk, sda3 is a partition (which contains an LVM physical volume), fedora-00 and fedora-01 are logical volumes, and each logical volume contains a LUKS encrypted volume.
How to identify LVM-over-LUKS or LUKS-over-LVM
1,350,499,117,000
Context Encrypting whole new external hard drive with Luks. I.e. it is not a system drive (will be used only to store data, not to boot the OS), and it is completely blank. Observation All descriptions that I found about how to achieve this go along the lines of: create a new partition, which is the same size as the whole disk encrypt that partition Some examples: From here: Creating a new encrypted partition: [...] Encrypting an existing partition Or here. Question Is it possible to encrypt the whole disk, instead of having one big encrypted partition? Probably the answer will be no, so the real question is why not? In other words What would happen if instead of typing sudo cryptsetup -v -y luksFormat /dev/sda1 I would type sudo cryptsetup -v -y luksFormat /dev/sda (without having created sda1)?
The cryptsetup FAQ mentions whole-disk encryption using LUKS. Basically, cryptsetup doesn’t care what the LUKS device is, partition, disk, or loop device, so you can use whichever is appropriate. sudo cryptsetup -v -y luksFormat /dev/sda will create a LUKS container using all of /dev/sda. Section 2.2 of the FAQ recommends this for external disks: Fully encrypted raw block device: For this, put LUKS on the raw device (e.g. /dev/sdb) and put a filesystem into the LUKS container, no partitioning whatsoever involved. This is very suitable for things like external USB disks used for backups or offline data-storage. Note that cryptsetup doesn’t need /etc/crypttab.
Encrypting whole disk with Luks (instead of one big encrypted partition)
1,350,499,117,000
I have recently discovered an exploit, where I(or assuming anyone) can re-encrypt my encrypted zip file without having to know the password: #zip --encrypt encrypted.zip -r dir1/ The above will prompt the user to enter a new password. Is there something I'm missing, or is this a known issue?
Zip archives can have multiple passwords for different contained files. Files within an archive are essentially independent of each other - they are compressed without regard for other files, and they are encrypted in the same fashion. Your encrypted.zip will have two (or more) encrypted segments, one with your original password and one with the new one. Trying to unzip the file would prompt for both passwords: $ unzip ../test.zip Archive: ../test.zip [../test.zip] file1 password: inflating: file1 inflating: file2 [../test.zip] newfile password: inflating: newfile The directory, the listing of file names, is not encrypted. This is not a bug, though it can be confusing and not all zip tools handle the situation well (particularly graphical tools).
Is this a zip encryption bug?
1,350,499,117,000
Is there any way to anonymize http requests through the command line? In other words, is it possible to wget a page without the requester's IP showing up?
One method of annoymizing HTTP traffic from the command line is to use tor. This article discusses the method, titled: How to anonymize the programs from your terminal with torify. General steps from article You can install the tor package as follows: Fedora/CentOS/RHEL $ sudo yum install tor Ubuntu/Debian $ sudo apt-get install tor Edit this file /etc/tor/torrc so that the following lines are present and uncommented: ControlPort 9051 CookieAuthentication 0 Start the tor service $ sudo /etc/init.d/tor restart Testing setup Real IP $ curl ifconfig.me 67.253.170.83 anonymized IP $ torify curl ifconfig.me 2>/dev/null 46.165.221.166 As you can see the ifconfig.me website thinks our IP address is now 46.165.221.166. You can tell tor to start a new session triggering a new IP address for us: $ echo -e 'AUTHENTICATE ""\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051 250 OK 250 OK 250 closing connection $ torify curl ifconfig.me 2>/dev/null 37.252.121.31 Do it again to get another different IP $ echo -e 'AUTHENTICATE ""\r\nsignal NEWNYM\r\nQUIT' | nc 127.0.0.1 9051 250 OK 250 OK 250 closing connection $ torify curl ifconfig.me 2>/dev/null 91.219.237.161 Downloading Pages $ torify curl www.google.com 2>/dev/null Browsing the internet via elinks $ torify elinks www.google.com       References Tor docs How to anonymize the programs from your terminal with torify
anonymous url navigation in command line?
1,350,499,117,000
From what little I know, in openpgp you have a private key which you keep locked or hidden somewhere and a public key which you can freely share with anybody. Now I have seen many people attaching .asc file. If I click on that, it reveals the other person's public key. Is having an .asc file nothing but using the putting your public key and then renaming it as something like signature.asc or is something else involved as well ? The .asc file seems to be an archive file (like a .rar or zip file) $ cat shirish-public-key.txt -----BEGIN PGP SIGNATURE----- publickeystring$ -----END PGP SIGNATURE----- How can I make/transform it into an .asc file ? I could just do - $ mv shirish-public-key.txt shirish.asc but I don't know if that is the right thing to do or not. Update - I tried but it doesn't work :( $ gpg --armor export shirish-public-key.txt > pubkey.asc gpg: WARNING: no command supplied. Trying to guess what you mean ... usage: gpg [options] [filename] Update 2 - Still it doesn't work - $ gpg --armor --export shirish-public-key.txt > pubkey.asc gpg: WARNING: nothing exported seems it can't figure out that the public key is in a text file . Update 3 - This is what the contents of the file look like See http://paste.debian.net/1022979/ But if I run - $ gpg --import shirish-public-key.txt gpg: invalid radix64 character 3A skipped gpg: invalid radix64 character 2E skipped gpg: invalid radix64 character 2E skipped gpg: invalid radix64 character 2E skipped gpg: invalid radix64 character 3A skipped gpg: invalid radix64 character 3A skipped gpg: invalid radix64 character 2E skipped gpg: CRC error; 1E6A49 - B36DCC gpg: [don't know]: invalid packet (ctb=55) gpg: read_block: read error: Invalid packet gpg: import from 'shirish-public-key.txt' failed: Invalid keyring gpg: Total number processed: 0 Seems something is wrong somewhere. FWIW gpg is version 2.2.5 from Debian testing (am running testing with all updates) $ gpg --version gpg (GnuPG) 2.2.5 libgcrypt 1.8.2 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Home: /home/shirish/.gnupg Supported algorithms: Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256 Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224 Compression: Uncompressed, ZIP, ZLIB, BZIP2
Usually, a .asc file is an ASCII-armored representation of key material (or a signature). Your shirish-public-key.txt looks like it’s just that, so if you’re sure it contains the right information you could simply rename it, as you suggest. (I doubt it contains your public key though — that should start with -----BEGIN PGP PUBLIC KEY BLOCK-----.) If a file contains “binary” data (which I’m guessing is what you mean when you say it looks like an archive), it’s not an ASCII file and wouldn’t usually be named with a .asc extension. To export your key in this format, from your keyring rather than an existing file (thus ensuring it contains the correct data), run gpg --armor --export YOUR_FINGERPRINT > pubkey.asc To make things easier, files are often named by their key id; in my case: gpg --armor --export "79D9 C58C 50D6 B5AA 65D5 30C1 7597 78A9 A36B 494F" > 0x759778A9A36B494F.asc There are various options you can use to tweak the exported data; for example, --export-options export-minimal will strip most signatures from the key, greatly reducing its size (but also its utility for people who care about the web of trust).
How do you generate an .asc file from pgp public key?
1,350,499,117,000
How is it possible, from bash or standard linux command-line tools, to XOR a file against a key? Something like: cat my1GBfile | xor my1MB.key > my1GBfile.encrypted Off-topic: I know the encryption is quite weak with this example, but I was just wondering if this is available from bash or standard linux command-line tools (or even better: from bash and cygwin, because I use both Linux and Windows).
bash can't deal with ASCII NUL characters, so you won't be doing this with shell functions, you need a small program for it. This can be done in just about any language, but it seems easiest to do it in C, perhaps like this: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *kf; size_t ks, n, i; long pos; unsigned char *key, *buf; if (argc != 2) { fprintf (stderr, "Usage: %s <key>\a\n", argv[0]); exit(1); } if ((kf = fopen(argv[1], "rb")) == NULL) { perror("fopen"); exit(1); } if (fseek(kf, 0L, SEEK_END)) { perror("fseek"); exit(1); } if ((pos = ftell(kf)) < 0) { perror("ftell"); exit(1); } ks = (size_t) pos; if (fseek(kf, 0L, SEEK_SET)) { perror("fseek"); exit(1); } if ((key = (unsigned char *) malloc(ks)) == NULL) { fputs("out of memory", stderr); exit(1); } if ((buf = (unsigned char *) malloc(ks)) == NULL) { fputs("out of memory", stderr); exit(1); } if (fread(key, 1, ks, kf) != ks) { perror("fread"); exit(1); } if (fclose(kf)) { perror("fclose"); exit(1); } freopen(NULL, "rb", stdin); freopen(NULL, "wb", stdout); while ((n = fread(buf, 1, ks, stdin)) != 0L) { for (i = 0; i < n; i++) buf[i] ^= key[i]; if (fwrite(buf, 1, n, stdout) != n) { perror("fwrite"); exit(1); } } free(buf); free(key); exit(0); } (this needs some more error checking, but oh well). Compile the above with: cc -o xor xor.c then run it like this: ./xor my1MB.key <my1GBfile >my1GBfile.encrypted
XOR a file against a key
1,350,499,117,000
I'm currently playing around and testing ZFS and I really like it. Now I am looking for the best way to use it as a replacement for my standard setup with luks-based full disk encryption. How is the concept of encryption in ZFS, do I encrypt a whole pool or just individual datasets? My idea is to boot, enter a passphrase and the rest as usual. I do not want to enter a passphrase for every dataset in my pool, so is it possible? I already tried using a ZFS pool inside a luks full disk encryption container, it works, but I guess this will be way less performant than using ZFS directly. I'm using Arch Linux with the "Stable" kernel and an NVME SSD. Thanks for clarification and recommended setups! Oh, one more: I read that you cannot encrypt existing datasets or pools, is that still the case?
Encryption was added to ZFS On Linux with the release of version 0.8. So you need at least that version. In ZFS, encryption is on a per-dataset basis, not on a pool - but, as with most things in ZFS, a dataset can inherit encryption properties from its parent (or from a defined encryptionroot instead of the parent). Setting encryption on a dataset in ZFS will not automatically encrypt any data already in it. As with enabling compression (or changing the compression type), only new data will be encrypted. to encrypt existing data, you can rsync or zfs send it to another dataset with encryption enabled, and then replace the old dataset with the new encrypted one. This may require the system to be in single-user mode (or, at least, to temporarily shut down any programs which may write to, or have files open on, the old dataset) I don't use encryption on any of my zpools, so that's about all I know about it. I'd strongly advise doing more research and reading the archives of the ZOL mailing lists and search for encryption related issues on the ZOL github repo. From the Encryption section of man zfs: Encryption Enabling the encryption feature allows for the creation of encrypted filesystems and volumes. ZFS will encrypt file and zvol data, file attributes, ACLs, permission bits, directory listings, FUID mappings, and userused / groupused data. ZFS will not encrypt metadata related to the pool structure, including dataset and snapshot names, dataset hierarchy, properties, file size, file holes, and deduplication tables (though the deduplicated data itself is encrypted). Key rotation is managed by ZFS. Changing the user's key (e.g. a passphrase) does not require re-encrypting the entire dataset. Datasets can be scrubbed, resilvered, renamed, and deleted without the encryption keys being loaded (see the zfs load-key subcommand for more info on key loading). Creating an encrypted dataset requires specifying the encryption and keyformat properties at creation time, along with an optional keylocation and pbkdf2iters. After entering an encryption key, the created dataset will become an encryption root. Any descendant datasets will inherit their encryption key from the encryption root by default, meaning that loading, unloading, or changing the key for the encryption root will implicitly do the same for all inheriting datasets. If this inheritance is not desired, simply supply a keyformat when creating the child dataset or use zfs change-key to break an existing relationship, creating a new encryption root on the child. Note that the child's keyformat may match that of the parent while still creating a new encryption root, and that changing the encryption property alone does not create a new encryption root; this would simply use a different cipher suite with the same key as its encryption root. The one exception is that clones will always use their origin's encryption key. As a result of this exception, some encryption-related properties (namely keystatus, keyformat, keylocation, and pbkdf2iters) do not inherit like other ZFS properties and instead use the value determined by their encryption root. Encryption root inheritance can be tracked via the read-only encryptionroot property. Encryption changes the behavior of a few ZFS operations. Encryption is applied after compression so compression ratios are preserved. Normally checksums in ZFS are 256 bits long, but for encrypted data the checksum is 128 bits of the user-chosen checksum and 128 bits of MAC from the encryption suite, which provides additional protection against maliciously altered data. Deduplication is still possible with encryption enabled but for security, datasets will only dedup against themselves, their snapshots, and their clones. There are a few limitations on encrypted datasets. Encrypted data cannot be embedded via the embedded_data feature. Encrypted datasets may not have copies=3 since the implementation stores some encryption metadata where the third copy would normally be. Since compression is applied before encryption, datasets may be vulnerable to a CRIME-like attack if applications accessing the data allow for it. Deduplication with encryption will leak information about which blocks are equivalent in a dataset and will incur an extra CPU cost per block written.
ZFS encrypted pool on Linux?
1,350,499,117,000
The qcow2 image file format for KVM can use AES encryption. The encryption is applied at the cluster level: Each sector within each cluster is independently encrypted using AES Cipher Block Chaining mode, using the sector's offset (relative to the start of the device) in little-endian format as the first 64 bits of the 128 bit initialisation vector. The cluster size can be set from 512 bytes to 2M (64K appears to be the default). One of the main issues with using qcow2 encryption is the performance hit for the CPU - every disk write or non-cached read needs to encrypt or unencrypt. What I'd like to know is does QEMU/KVM use the Intel AES instructions to mitigate the performance hit if the host CPU has them? If so, does usage or performance depend significantly on cluster size? Intel® AES instructions are a new set of instructions available beginning with the all new 2010 Intel® Core™ processor family based on the 32nm Intel® microarchitecture codename Westmere. These instructions enable fast and secure data encryption and decryption, using the Advanced Encryption Standard (AES) which is defined by FIPS Publication number 197. Since AES is currently the dominant block cipher, and it is used in various protocols, the new instructions are valuable for a wide range of applications.
At least with the Fedora 20 package qemu-img (1.6.2, 10.fc20) does not use AES-NI for AES crypto. Confirming One can verify it like this: Does the CPU have AES-NI? $ grep aes /proc/cpuinfo -i For example my Intel Core 7 has this extension. Install the necessary debug packages: # debuginfo-install qemu-img Run qemu-img in a debugger: $ gdb --args qemu-img convert -o encryption -O qcow2 disk1.img enc1.qcow2 Set a break-point in a well known qemu encryption function that is not optimized for AES-NI: (gdb) b AES_encrypt Breakpoint 1 at 0x794b0: file util/aes.c, line 881. Run the program: (gdb) r Starting program: /usr/bin/qemu-img convert -o encryption -O qcow2 disk1.img enc1.qcow2 Results In my testing it does stop there: Breakpoint 1, AES_encrypt (in=0x7ffff7fabd60 "...", key=0x555555c1b510) at util/aes.c:881 881 const AES_KEY *key) { (gdb) n 889 assert(in && out && key); (gdb) n 881 const AES_KEY *key) { (gdb) n 889 assert(in && out && key); (gdb) n 896 s0 = GETU32(in ) ^ rk[0]; (gdb) n 897 s1 = GETU32(in + 4) ^ rk[1]; Meaning that, indeed, Intel AES instructions are not used. My first thought was that qemu-img perhaps just uses libcrypto such that AES-NI is automatically used, when available. qemu-img even links against libcrypto (cf ldd $(which qemu-img)) - but it does not seem to use it for AES crypto. Hmm. I derived the breakpoint location via grepping the QEMU source code. On Fedora you can get it like this: $ fedpkg clone -a qemu $ cd qemu $ fedpkg source $ tar xfv qemu-2.2.0-rc1.tar.bz2 $ cd qemu-2.2.0-rc1 NOTE: gdb can be exited via the quit command.
Does QEMU/KVM use Intel AES instructions for encrypted qcow2 images if the host CPU has them?
1,350,499,117,000
I have installed GRUB2 to an encrypted boot partition, as detailed here. The chosen hashing algorithm for my luksFormat is sha512, with the default iter-time (which is 2 seconds). This encrypted partition takes a little over 2 seconds to unlock if done from the command line (either from archiso or from the running system), but GRUB takes 10.5 seconds, on average, to unlock it. This is slower than acceptable for my scenario. I found other people having the same problem here and here. In the second link, user frostschutz has posted some hints about what might be causing this, of which I think 2 are very valid: 1) The CPU might be running in power-saving mode during the early GRUB unlocking 2) GRUB might be using a hashing implementation which is much slower than the system. He did a benchmark which can be found here. As encrypting the boot partition appears to be becoming more common, and there exists no satisfactory answer for this problem yet, I thought I'd ask about this. What can be done, apart from decreasing the iteration count (which substantially lowers security in an offline attack scenario), to counter this (much) slower decryption time by the GRUB bootloader? I'd like to at least pinpoint the exact cause. Is there a way to check (and maybe alter) the CPU clock in the bootloader screen? I know GRUB has a shell; I opened it and tried cat /proc/cpuinfo but it fails with "/proc not found" or something like that. I also tried cpuid, and whilst it doesn't fail, it also returns nothing. As additional information, I got these timings: GRUB takes 9 seconds or longer to unlock the boot partition (/boot) after typing the password and pressing Enter. The Kernel appears to take about 7 seconds to unlock the root partition (/). Again, this is timed after pressing Enter. The Kernel unlocks and mounts the boot partition (/boot) via crypttab in just over 2 seconds. Updates: I tried SHA256 hashing and it took longer (13 seconds). This probably indicates that GRUB must be using 64bits, as can be deduced from here, https://security.stackexchange.com/a/40218/91904 and in frostschutz's answer. Also tried SHA1 and it takes 11.5 seconds. It doesn't seem to make a difference whether AES256 or AES512 is used It also doesn't matter which filesystem is in use for the boot partition.
GRUB is early boot. There is no OS, no Linux available yet, although we tend to forget that since GRUB does so many amazing-crazy things all by itself. So a /proc not found message is not surprising. SHA512 benefits a lot from 64bit instructions but GRUB might not be able to use those yet. Try SHA256 or SHA1, maybe they work better for GRUB. It matters little which hash spec you use with LUKS as the iter counts will just be adapted accordingly. See How to change the hash-spec and iter-time of an existing dm-crypt LUKS device? on how to try that w/o re-encrypting everything. GRUB seems to be using some variant of gcrypt library for its hashing needs. I don't know if my very old benchmark is still valid. Back when I tested it was not the fastest library (at least the way it's used by cryptsetup benchmark) and there were surprisingly large differences. So if you are not using gcrypt with your cryptsetup binary that might be another reason for difference in time to unlock. Maybe you'll just have to experiment until you find a value that works for you. As encrypting the boot partition appears to be becoming more common, For all the wrong reasons... people tamper your /boot, people tamper your bootloader just as easily. GRUB only supports the most direct scheme, what's the point if it falls to a cheap keylogger?
GRUB takes too long to unlock the encrypted boot partition
1,350,499,117,000
I am a big fan of linux and like trying out new distros now and then. I usually have my home folders and roots in a lvm atop an encrypted partition, but this tends to become cumbersome with every initramfs creation process being more alien than the last one. I value privacy, but most of my valuable information or personal is stored in the home folders. Moreover, I partitioned using GPT, so multiple partitions are not that hard to setup even outside a lvm. So the question is: Is root crypting and lvm-ing of "/" worth it, especially with all the early userspace hassle I have to deal with?
First of all the hassle with encrypted root and early userspace is typically already handled by your distribution (as far as i know Fedora, Debian, Ubuntu and OpenSUSE support encrypted root out of the box). That means you don't have to care for the setup itself. One reason for encrypting / is just to be sure you don't leak any information at all. Think about programs writing temporary data into /tmp, log files containing sensitive information like username/passwords in /var/log or configuration files containing credentials like a password in /etc/fstab or some commands in the shell history of the root user. Using LVM instead of partitions has one great benefit, you can easily resize/rename/remove logical volumes without the need to re-partition your disk itself, it is just more convenient than using partitions (GPT or MBR)
Any reason for encrypted /?
1,350,499,117,000
A vulnerability scan showed that in a Debian 10 system, insecure MAC algorithms are in use: [email protected],[email protected],[email protected],hmac-sha1 When I do ssh -Q mac, I get the following results: hmac-sha1 hmac-sha1-96 hmac-sha2-256 hmac-sha2-512 hmac-md5 hmac-md5-96 [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] In the /etc/ssh/ssh_config file there is line that's commented out: # MACs hmac-md5,hmac-sha1,[email protected] There is no mention of umac-64-etm or hmac-sha1-etm in the file. In /etc/ssh/sshd_config there is no MAC keyword at all. How can I disable these weak HMACs?
The list of supported MAC algorithms is determined by the MACs option, both in ssh_config and in sshd_config. If it's absent, the default is used. If you want to change the value from the default, either edit the existing entry or add one if it isn't present. For example: MACs hmac-sha2-256,hmac-sha2-512,[email protected],[email protected],[email protected] Recent enough versions of OpenSSH (and Debian 10 is recent enough) also allow a differential specification, for example to disable all short MACs and MACs based on MD5 or SHA-1: MACs -*md5*,*sha1,*sha1-*,*-64,*-96 Note that none of the default algorithms are actually insecure. A 64-bit MAC would be very weak for offline use, but it's acceptable for network messages which are only valid within one connection which would time out before anyone can break even a 64-bit MAC. (It's a sign that they're still in the default list for OpenSSH, even though OpenSSH is very proactive about security.) MD5 and SHA1 have weaknesses that make them insecure as hashes, but the HMAC construction doesn't care about these weaknesses. I would recommend keeping at least hmac-sha1 for interoperability with older systems unless you absolutely need to disable it for compliance (this would be about compliance and not about security).
How to disable weak HMAC Algorithms? Not found in ssh_config or sshd_config file
1,350,499,117,000
I read man vim, :h -x and :h encryption none of this actually says what algorithm it's encrypted with.
:h 'cryptmethod' says that PkZip and Blowfish (new in Vim 7.3) are possible encryption methods. A look around FEAT_CRYPT in vim/src/misc2.c confirms it. The weak encryption method is documented in PKWARE's zip file format documentation, and the new strong encryption is documented on Bruce Schneier's Blowfish page.
What encryption does vim -x use?
1,350,499,117,000
Is it possible to convert LUKS2 to LUKS version 1, and by extension, change the use of features that would block such a conversion? Fedora 30 uses LUKS2 by default, however I ran into a situation where I need to stick with LUKS version 1. Specifically, Relax-and-Recover (rear) does not support LUKS2 at the moment. Documentation mentions that converting between LUKS2 and LUKS1 is possible under certain conditions: In-place conversion form LUKS1 To allow easy testing and transition to the new LUKS2 format, there is a new convert command that allows in-place conversion from the LUKS1 format and, if there are no incompatible options, also conversion back from LUKS2 to LUKS1 format. Note this command can be used only on some LUKS1 devices (some device header sizes are not supported). This command is dangerous, never run it without header backup! If something fails in the middle of conversion (IO error), the header is destroyed. (Note that conversion requires move of keyslot data area to a different offset.) To convert header in-place to LUKS2 format, use $ cryptsetup convert --type luks2 To convert it back to LUKS1 format, use $ cryptsetup convert --type luks1 You can verify LUKS version with luksDump command. $ cryptsetup luksDump Note that some LUKS2 features will make header incompatible with LUKS1 and conversion will be rejected (for example using new Argon2 PBKDF or integrity extensions). Some minor attributes can be lost in conversion. That last point is a problem as it seems that feature is used by default at least on Fedora. $ sudo cryptsetup convert /dev/sda3 --type luks1 WARNING! ======== This operation will convert /dev/sda3 to LUKS1 format. Are you sure? (Type uppercase yes): YES Cannot convert to LUKS1 format - keyslot 0 is not LUKS1 compatible. $ sudo cryptsetup luksDump /dev/sda3 LUKS header information Version: 2 Epoch: 3 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 974b19f8-021a-46b6-a089-a46e06e6e746 Label: (no label) Subsystem: (no subsystem) Flags: (no flags) Data segments: 0: crypt offset: 16777216 [bytes] length: (whole device) cipher: aes-xts-plain64 sector: 512 [bytes] Keyslots: 0: luks2 Key: 512 bits Priority: normal Cipher: aes-xts-plain64 Cipher key: 512 bits PBKDF: argon2i Time cost: 4 Memory: 973984 Threads: 4 Salt: af 33 7e 3b 6c bb 55 dc e3 dc 2b 07 c5 9e c3 6d f2 c9 08 be 2f 1d 8b 78 8a 33 65 90 41 e3 05 10 AF stripes: 4000 AF hash: sha256 Area offset:32768 [bytes] Area length:258048 [bytes] Digest ID: 0 Tokens: Digests: 0: pbkdf2 Hash: sha256 Iterations: 100361 Salt: d9 30 b6 7f 60 d0 e0 19 39 f6 a2 38 ae 22 88 43 1e 5c 74 75 e6 b5 dd db a9 e7 29 1a 74 64 9c 0f Digest: ae 06 29 5f 71 49 bd c8 75 de 53 e8 95 94 d3 38 57 43 5f 0e 1e ac 6d 59 fb 34 a3 97 e4 5a 94 0c
Converting LUKS1 to LUKS2, then back to LUKS1 works just fine. It's starting out with LUKS2 then converting to LUKS1 that causes problems. Apparently, cryptsetup convert is unable to convert between LUKS2 argon2i keys and LUKS1 pbkdf2 keys. Setup: # truncate -s 100M luks1.img # truncate -s 100M luks2.img # cryptsetup luksFormat --type luks1 luks1.img # cryptsetup luksFormat --type luks2 luks2.img Test with originally luks1: # cryptsetup convert luks1.img --type luks2 WARNING! ======== This operation will convert luks1.img to LUKS2 format. Are you sure? (Type uppercase yes): YES # cryptsetup convert luks1.img --type luks1 WARNING! ======== This operation will convert luks1.img to LUKS1 format. Are you sure? (Type uppercase yes): YES We've got LUKS1 -> LUKS2 -> LUKS1 working. Test with originally luks2: # cryptsetup convert luks2.img --type luks1 WARNING! ======== This operation will convert luks2.img to LUKS1 format. Are you sure? (Type uppercase yes): YES Cannot convert to LUKS1 format - keyslot 0 is not LUKS1 compatible. Same story for the originally luks1.img, if you add another key while in LUKS2 format. But since we're able to add argon2i keys to originally luks1, perhaps we can add pbkdf key to originally luks2? There were some weird issues with that, too, but after some trial and error, I ended up with: # cryptsetup luksConvertKey --pbkdf=pbkdf2 luks2.img Enter passphrase for keyslot to be converted: I have a sudden craving for butternut biscuits. And then it works (provided that was the only key). # cryptsetup convert luks2.img --type luks1 WARNING! ======== This operation will convert luks2.img to LUKS1 format. Are you sure? (Type uppercase yes): YES But it's not quite the same as the originally LUKS1 header (in particular, Payload offset: 32768 stands out). Now, LUKS1 changed their data offset before (originally it was not MiB aligned) so third-party software should be able to handle unusual offsets, but you never know. LUKS2 also has other features that make conversions impossible (without oldfashioned re-encrypting) so the method described here only covers the most simple case.
Convert LUKS2 back to LUKS version 1
1,367,338,736,000
I'm currently using thunderbird with gnupg to read encrypted emails. If I understand the swapping behavior correctly, the memory pages containing the decrypted emails might be swapped out and leave traces on the hard disk which may in theory later be recovered forensically. While it is certainly possible to just use an encrypted swapfile or disable swapping globally for the duration of using sensitive files, it impacts performance, might be forgotten and requires root privileges. Is it possible to mark certain files or programs as not to be swapped? Even without root access? Could one write an application which can be distributed to technically naive users and whose memory contents are never swapped to disk?
In the comments, I suggested you create a cgroup, set memory.swappiness to zero (to minimize swapping) and run your application inside of that. If you did that, your application probably wouldn't swap unless you were running so incredibly low on physical memory that swapping pages for programs in that cgroup was the only way to make enough physical memory available. To do this on RHEL 6.5: Ensure the libcgroup package is installed. This gives you access to userspace tools like cgcreate and cgexec. Start and enable the cgconfig service so that changes to cgroup configuration are persistent between reboots. On RHEL this service should also mount the required filesystems underneath the /cgroup tree. Create the cgroup with cgcreate -g memory:thunderbird Set swappiness to zero in this group with cgset -r memory.swappiness=0 thunderbird Use cgsnapshot -s > /etc/cgconfig.conf to save an updated persistent configuration for the cgconfig service (all changes up until now have been runtime changes. You'll probably want to save the default config file somewhere and give it a once-over before making it the persistent configuration. You can now use cgexec to start desired applications within the thunderbird cgroup: [root@xxx601 ~]# cgexec -g memory:thunderbird ls anaconda-ks.cfg a.out foreman.log index.html install.log install.log.syslog node.pp sleep sleep.c ssl-build stack test [root@xxx601 ~]# I don't have thunderbird actually installed otherwise I would have done that. Not sure why the formatting of the above is messed up. One alternative to cgexec would be to start thunderbird and add the PID to the tasks file for the application. For example: [root@xxx601 ~]# cat /cgroup/memory/thunderbird/tasks [root@xxx601 ~]# pidof httpd 25926 10227 10226 10225 10163 10162 10161 10160 10159 10157 10156 10155 10152 10109 [root@xxx601 ~]# echo 25926 > /cgroup/memory/thunderbird/tasks [root@xxx601 ~]# cat /cgroup/memory/thunderbird/tasks 25926 Again, it's bears mentioning that this doesn't technically prevent swapping but short of modifying the application itself, it's probably your best bet. I've just now found memory.memsw.limit_in_bytes which seems like it might be a more direct control on forcing there to be no swapping but I haven't played around with it enough to really feel comfortable saying that it fixes your problem completely. That said, it might be something to look into after this. The real answer would be to have the application mlock sensitive information to get around this sort of concern. I'm willing to bet an application like Thunderbird, though, does do that but I don't know enough about the internals to comment on that.
Can swapping be disabled on the application level?
1,367,338,736,000
I am working on my yocto distribution including cryptsetup in the 2.3.2 version I am running such distribution on a board with 1 GB RAM and I am incurring in an "out of memory" error trying to open an encrypted partition that I am not able to properly debug. Any ideas? My distro runs from an mSD with 3 partitions; the third one (30 MB) is the encrypted one. I used the steps described on the ArchLinux guide to encrypt that partition, with ext3 instead of ext4 # cryptsetup -y -v luksFormat /dev/sda2 # cryptsetup open /dev/sda2 cryptroot # mkfs.ext3 /dev/mapper/cryptroot But trying to open that partition on my board raises an error: cryptsetup --debug open /dev/mmcblk0p3 cryptroot # cryptsetup 2.3.2 processing "cryptsetup --debug open /dev/mmcblk0p3 cryptroot" # Running command open. # Locking memory. # Installing SIGINT/SIGTERM handler. # Unblocking interruption on signal. # Allocating context for crypt device /dev/mmcblk0p3. # Trying to open and read device /dev/mmcblk0p3 with direct-io. # Initialising device-mapper backend library. # Trying to load any crypt type from device /dev/mmcblk0p3. # Crypto backend (OpenSSL 1.1.1k 25 Mar 2021) initialized in cryptsetup library version 2.3.2. # Detected kernel Linux 4.1.35-rt41 ppc. # Loading LUKS2 header (repair disabled). # Acquiring read lock for device /dev/mmcblk0p3. # Opening lock resource file /run/cryptsetup/L_179:3 # Verifying lock handle for /dev/mmcblk0p3. # Device /dev/mmcblk0p3 READ lock taken. # Trying to read primary LUKS2 header at offset 0x0. # Opening locked device /dev/mmcblk0p3 # Veryfing locked device handle (bdev) # LUKS2 header version 2 of size 16384 bytes, checksum sha256. # Checksum:43e122216ab19330fdfb6d2f9d7b586c4e5189884aef24be884e7159228e9ee5 (on-disk) # Checksum:43e122216ab19330fdfb6d2f9d7b586c4e5189884aef24be884e7159228e9ee5 (in-memory) # Trying to read secondary LUKS2 header at offset 0x4000. # Reusing open ro fd on device /dev/mmcblk0p3 # LUKS2 header version 2 of size 16384 bytes, checksum sha256. # Checksum:4ed9a44c22fde04c4b59a638c20eba6da3a13e591a6a1cfe7e0fec4437dc14cc (on-disk) # Checksum:4ed9a44c22fde04c4b59a638c20eba6da3a13e591a6a1cfe7e0fec4437dc14cc (in-memory) # Device size 32505856, offset 16777216. # Device /dev/mmcblk0p3 READ lock released. # Only 1 active CPUs detected, PBKDF threads decreased from 4 to 1. # Not enough physical memory detected, PBKDF max memory decreased from 1048576kB to 255596kB. # PBKDF argon2i, time_ms 2000 (iterations 0), max_memory_kb 255596, parallel_threads 1. # Activating volume cryptroot using token -1. # Interactive passphrase entry requested. Enter passphrase for /dev/mmcblk0p3: # Activating volume cryptroot [keyslot -1] using passphrase. device-mapper: ioctl: 4.31.0-ioctl (2015-3-12) initialised: [email protected] # dm version [ opencount flush ] [16384] (*1) # dm versions [ opencount flush ] [16384] (*1) # Detected dm-ioctl version 4.31.0. # Device-mapper backend running with UDEV support enabled. # dm status cryptroot [ opencount noflush ] [16384] (*1) # Keyslot 0 priority 1 != 2 (required), skipped. # Trying to open LUKS2 keyslot 0. # Keyslot 0 (luks2) open failed with -12. Not enough available memory to open a keyslot. # Releasing crypt device /dev/mmcblk0p3 context. # Releasing device-mapper backend. # Closing read only fd for /dev/mmcblk0p3. # Unlocking memory. Command failed with code -3 (out of memory).
LUKS2 uses Argon2i key derivation function which is memory-hard -- meaning it requires a lot of memory to open the device to prevent (or at least make it harder) brute force attacks using GPUs. You can check how much memory you need to open your device using cryptsetup luksDump /dev/sda2, look for the line Memory: 755294 under Keyslots. When creating the device, cryptsetup checks how much memory is available and adjusts the amount required for opening it accordingly, but if you did create the LUKS device from a different computer (for example when formatting the SD card on a desktop) or even on the same machine with more memory available, it's possible you simply don't have enough memory now. And we are talking only about RAM, swap is not used in this case. I recommend re-creating the LUKS device with --pbkdf pbkdf2 to switch to the "old" (used to be default in LUKS1) key derivation function PBKDF2 which doesn't use extra memory. Alternatively you can also use --pbkdf-memory <num> to force lower amount of memory for the default Argon2i.
Open: cryptsetup out of memory ("Not enough available memory to open a keyslot.")
1,367,338,736,000
I want to know how can I create an encrypted password in Ubuntu 14.04 LTS. Tried this: makepasswd --crypt-md5 password_here It did not work for me. It is throwing this Error: sysadmin@localhost:~$ makepasswd --crypt-md5 admin123 makepasswd: Non-argument options specified: admin123 makepasswd: For more information, type: makepasswd --help I want to add those encrypted password in one of the installation so I need the way of doing it.
# echo -n admin123 | makepasswd --crypt-md5 --clearfrom - admin123 $1$ZUNNSLzQ$XsViFC1bhucsr3f8AzMPt/ As commented bellow this command is unsecure. True method - write password in file with text editor, and read password from file.
How to Create an Encrypted Password
1,367,338,736,000
Is there any way to encrypt a directory using gpg? It seems to only accept files as arguments.
Why not tar the files to be encrypted and then encrypt the tarball?
Encrypt directory with GnuPG?
1,367,338,736,000
So I created a gpg encrypted file with password: gpg -c passwords.txt.gpg how can I open it with vi, edit it, then close it? (So that no passwords.txt file will be created, the decrypted passwords.txt is only in the memory! - better: after closing the passwords.txt.gpg file, the memory should be cleaned, so it shouldn't contain unencrypted passwords).
Original Answer The gnupg plugin for Vim does this: This script implements transparent editing of gpg encrypted files. The filename must have a ".gpg", ".pgp" or ".asc" suffix. When opening such a file the content is decrypted, when opening a new file the script will ask for the recipients of the encrypted file. The file content will be encrypted to all recipients before it is written. The script turns off viminfo and swapfile to increase security. EDIT #1 As of 2016-07-02, the original gnupg plugin is now no longer being maintained: Due to the lack of time I'm not able to continue the development of this script. James McCoy took over development. New versions can be found at vimscript #3645. There is however a new version: gnupg.vim - Plugin for transparent editing of gpg encrypted files. : vim online
How to edit a .gpg file with vi?
1,367,338,736,000
I want to store some data encrypted to carry around with me (this includes some scans of relevant paperwork, my TAN List for online banking, my gnupg and ssh keys and stuff like that). So not really a huge amount of data but also more than a little textfile. What I want is a container I can put on my thumbdrive to carry things around in that is fully encrypted. A few more requirements: Strong Encryption, so no ZIP with passwords I want to sync the container to more than one location (in case the thumbdrive breaks or is stolen for example) so I cannot just create another dmcrypt partition on the thumbdrive I want to open the container from my GNOME environment without a lot of terminal fiddling. Not that I don't like terminals, but I want a certain level of convenience. (Right-clicking in nautilus to "mount" is OK, entering 3 commands in a terminal is not) Bonus: Something I can open from Windows and/or OSX as well
Truecrypt ticks all of those boxes. You have the option of either encrypting the whole USB key, or just having an encrypted container (as a file) It can then be decrypted regardless of platform, and can be configured to automount.
Portable encrypted container
1,367,338,736,000
Trying to create GPG keys which will be used for an apt repository hosted on my Centos7 box. I created a new user "apt", and then tried to create the keys, but at the very end, it states that I need a pass phrase, but then instantly closes stating cancelled by user. No it wasn't! I have since successfully repeated these same steps root and as my standard username which happens to be in the wheels group. Two questions: Is it a good idea to use different gpg keys for different uses such as this apt repository, and should keys ever be created as root? Why am I not able to create a gpg key for this user? Do I need to first create some other key for this user? Thanks [apt@devserver ~]$ gpg --gen-key gpg (GnuPG) 2.0.22; Copyright (C) 2013 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) Requested keysize is 2048 bits Please specify how long the key should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 1y Key expires at Thu 12 Jul 2018 04:32:05 PM UTC Is this correct? (y/N) y GnuPG needs to construct a user ID to identify your key. Real name: somename Email address: [email protected] Comment: You selected this USER-ID: "somename <[email protected]>" Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O You need a Passphrase to protect your secret key. gpg: cancelled by user gpg: Key generation canceled. [apt@devserver ~]$
As to the "cancelled by user" error: GnuPG tries to make sure it's reading the passphrase directly from the terminal, not (e.g.) piped from stdin. To do so, it tries to open the tty directly. Unfortunately, file permissions get in the way — the tty device is owned by the user you log in as. So only that user and root can open it. GnuPG appears to report the error incorrectly, saying you canceled (when in fact it got a permission denied). As to if you should have a separate key for the repository: yes. There are a couple of reasons that come to mind: A repository can be maintained by more than one person. All of them will need access to the key. You obviously don't want to give them access to your personal key. The software processing new packages will need access to the key. For many repositories, that means you have to keep the key available on an Internet-connected machine. This necessitates a lower level of security than you'd ideally have on your personal key. If you're processing uploads automatically, you may even need to store the key with no passphrase. Obviously lowers security. In case of compromise of your personal key, it's nice to only have to revoke that. Same with compromise of the repository key. It makes revoking a compromised key cheaper. It's pretty normal to use your personal key to sign the repository key. As to running key generation as root: not ideal (don't run things as root without good reason), but likely not really an issue.
gpg: cancelled by user
1,367,338,736,000
I've got a laptop which I haven't used since the last summer vacation: I did put Debian 7 on it and used Debian's feature to fully encrypt the disk, besides a tiny bootloader (or a tiny partition) I guess (not too sure which encryption this is nor how to find out). I do know the password of the encrypted filesystem so the system boots, but I'm stuck the login prompt: I did forgot my password(s). Seen that I know the password of the encrypted filesystem, I take it I can boot from a Live CD (or even maybe from the Debian install CD?) and somehow "mount" the encrypted partition. If that's the case, can someone explain me how to do this? (knowing that I've never mounted an encrypted partition / filesystem manually)
Full disk encryption is usually done using the dm-crypt Device Mapper target, with a nested LVM (Logical Volume Manager) inside. So to reset your password you'll have to Unlock/open the crypto container; this is done using cryptsetup Activate the logical volumes; vgchange is used for this. Usually you won't need to care about this. Just let the initrd provided by your distribution do the job but tell it not to start /sbin/init but something else — a shell would be good. Simply append init=/bin/sh to your kernel's command line in your boot loader (with GRUB you could press E with the appropriate boot entry selected to edit the entry). Then your kernel should boot up normally, booting into the initrd which should ask for your passphrase and set up your file-systems but instead of booting the system up drop you into a shell. There you'll have to remount / read-write: mount -o rw,remount / reset your password using passwd <user> (since you're root you won't get prompted for the old one) remount / read-only: mount -o ro,remount / (skipping this might confuse your init scripts) Start the regular init with exec /sbin/init (or simply reboot -f). If this does not work, you'll have to take the approach with greater effort and do it from "outside", a.k.a. booting a Live CD. Usually this should be possible by using the Debian install CD — the tools should be installed, since the installer somehow has to set up encryption which uses the same schema: Boot a Live CD Open the encrypted partition by issueing # cryptsetup luksOpen /dev/<partition> some_name where <partition> should be your encrypted partitions name (sda2, probably). some_name is just… some name. This will prompt you for the disk's encryption passphrase and create a block device called /dev/mapper/some_name. Activate the logical volumes. This should usually work by issueing # vgscan # vgchange -ay This will create block device files for every logical volume found in the LVM in /dev/mapper/. Mount the volume containing your / file system: # mount /dev/mapper/<vgname>-<lvname> /mnt where <vgname> and <lvname> are the names of the volume group and the logical volume. This depends on the way distributions set it up, but just have a look into /dev/mapper/, normally names are self-explanatory. Change your password with passwd <user> accordingly.
How to reset password on an encrypted fs?
1,367,338,736,000
Now I mount an encrypted folder: open browser and login to NAS gui click Control panel -> Shared Folder > Encryption > Mount enter key after folder is mounted: rsync -ah --progress --delete /path/* admin@ipadress:/volume1/path/ Can I bypass 1.-3. and use ssh only?
Use the gui to mount the encrypted directory, then login to the synology as root over ssh and type mount. You will see a line like /volume1/@mycryptdir@ on /volume1/mycryptdir type ecryptfs (rw,relatime,ecryptfs_fnek_sig=88...,ecryptfs_sig=88...,ecryptfs_cipher=aes,ecryptfs_key_bytes=32) This shows your directory /volume1/mycryptdir is implemented on an underlying /volume1/@mycryptdir@ directory using ecryptfs. Unmount the directory with the gui, then try the following command: # ecryptfs-add-passphrase Passphrase: Type in the cleartext passphrase you originally used (not the .key file). It will reply Inserted auth tok with sig [88...] into the user session keyring Now type the mount command using the options you saw before. You will need to create the mount point directory: # mkdir /volume1/mycryptdir # mount /volume1/\@mycryptdir\@/ /volume1/mycryptdir/ -t ecryptfs -o rw,relatime,ecryptfs_fnek_sig=88...,ecryptfs_sig=88...,ecryptfs_cipher=aes,ecryptfs_key_bytes=32 Your filesystem should now be mounted and useable. You should now clear the password from the in-memory keyring: # keyctl clear @u When you have finished, unmount the directory with umount /volume1/mycryptdir.
How can I mount encrypted folder via SSH in Synology NAS?
1,367,338,736,000
When you run luksDump on a LUKS device, I get this: $ sudo cryptsetup luksDump /dev/sda1 LUKS header information Version: 2 Epoch: 3 Metadata area: 16384 [bytes] Keyslots area: 16744448 [bytes] UUID: 4640c6e4-[…] Label: (no label) Subsystem: (no subsystem) Flags: (no flags) […] I’s quite obvious what “version” refers to (the current best is v2, so this is what you should aim for) and I’ve seen values for Epoch from 3 to 5. However, what does Epoch refer to, actually? And what value should I aim at? Does it matter (security-wise) what number is stated there? Is it bad if it is still Epoch 3 e.g.? Can one upgrade that Epoch? I’ve searched the web and the FAQ for information, but the word epoch is not mentioned there.
The Epoch increases every time you change anything in your LUKS header (like when adding or removing keys, etc.). The LUKS2 header specification states: uint64_t seqid; // sequence ID, increased on update seqid is a counter (sequential number) that is always increased when a new update of the header is written. The header with a higher seqid is more recent and is used for recovery (if there are primary and secondary headers with different seqid, the more recent one is automatically used). Why this is called a "sequence ID" in code and technical documentation, but uses the term "Epoch" when shown to the end user, remains a mystery. That it is in fact the same thing, can be seen if you read the fine source, which prints seqid as Epoch: log_std(cd, "Epoch: \t%" PRIu64 "\n", hdr->seqid); tl;dr You can safely ignore the Epoch, it is a harmless counter with no specific meaning.
What is the epoch of LUKS that is shown when running luksDump?
1,367,338,736,000
I am planing to backup data via sending btrfs snapshots to an online storage. The storage is mounted as a LUKS encrypted container file on a cifs share. Later transfers will be reasonably fast, but for the first one is 1,3TB, which, when I use tc to leave me with a reasonable amount of upstream, will take 23 days. Now, in theory, my connection could handle that, but reconnections are possible. As far as I understand, this would force me to start all over again, if I just use btrfs send ... | btrfs receive ... Is there any save, that is, resumable way to do this? I found buttersink, but it only seems to allow resume for S3. Any ideas? Feel free to use the comments to suggest a completely different solution. It is a Hetzner Storagebox (https://www.hetzner.de/de/hosting/storagebox/bx40). I have FTP, FTPS, SFTP, SCP (but not SSH and paramiko also doesn't work), Samba/CIFS, HTTPS, WebDAV access. The storage is not to be trusted with the unencrypted data. Free space on both sites is not excessive. There will be lots of changing smaller files, so duplicity without a regular full backup (that would take a month again) does not seem to be feasible. For the same reason, rsync would most likely be slow when comparing the local version with the one locally mounted from remote. EncFS seems to be unsave, since the other side will potentially be able to gather multiple versions of a single file over time.
As I understand it, your remote storage is exposed as a filesystem. I don't use btrfs myself but I assume the snapshots are equivalent to one large "full backup" file followed by a number of smaller "incremental" files. On that basis I'd still go with rsync because it's restartable. You can't use its snazzy delta differences algorithm unless there's an rsync server available on the remote host, but you can tell rsync to assume the source file hasn't changed and to continue after a break from the byte offset it had reached: test -t 2 && progress=--progress rsync -av $progress --partial --append --sparse /path/to/source.img /path/to/remote/storage/ If you can usefully gzip your source file before transferring it, do so. (Neither --rsyncable nor rsync -z is relevant for what rsync sees as a local to local file transfer.)
Resumable transfer for btrfs send
1,367,338,736,000
I want to boot the Linux from the /boot partition, and also want to encrypt this /boot partition. [ AFAIK, Grub is unable to find the kernel and initrd from an truecrypted partition or cryptsetup encrypted boot partition. ] Is there any way to do so ?
Yes, using Grub2 you can do this: It has been patched to support not only AES, Twofish, Serpent and CAST5 encryption, but a number of hashing routines such as SHA1, SHA256, SHA512, and RIPEMD160. There is also support for the LUKS on-disk encryption format. Check out this xercestech post for a full manual walkthrough, but in a nutshell everything is encrypted except for the actual bootloader, which you could have on a USB stick if you really wanted to stay safe. The LUKS patches to support grub are here.
Encrypted Booting
1,367,338,736,000
Releases of gnupg from 2.1.16 (currently 2.1.17) block waiting for entropy only on first invocation. Note: this isn't an attempt to generate a key, just to decrypt a file and start the agent. The first time gpg-agent is started, either directly with gpg2 file.gpg or using an application like pass, pinentry appears and once I enter my passphrase and hit Enter it hangs for around 15s. All subsequent calls, within the window of the default-cache-ttl, are executed immediately. Running in --debug-all mode, the period where the hang occurs prints1: gpg: DBG: chan_6 <- S PROGRESS need_entropy X 30 120 gpg: DBG: chan_6 <- S PROGRESS need_entropy X 120 120 gpg: DBG: chan_6 <- S PROGRESS need_entropy X 30 120 gpg: DBG: chan_6 <- S PROGRESS need_entropy X 120 120 gpg: DBG: chan_6 <- S PROGRESS need_entropy X 30 120 ... I installed rng-tools to supplement the entropy pool: cat /proc/sys/kernel/random/entropy_avail 4094 and compared with a machine with the same version of gnupg that did not have rng-tools or haveged installed, that exhibits no delay: cat /proc/sys/kernel/random/entropy_avail 3783 So there appears to be sufficient entropy in the pool. This was tested on kernels 4.8.13 and 4.9. Does gpg use a different pool? How can I provide sufficient entropy, or otherwise eliminate the 15s delay when starting the agent? 1. The full debug log.
I think I know what's going on. In gnupg's agent/gpg-agent.c, this function processes messages from libgcrypt. /* This is our callback function for gcrypt progress messages. It is set once at startup and dispatches progress messages to the corresponding threads of the agent. */ static void agent_libgcrypt_progress_cb (void *data, const char *what, int printchar, int current, int total) { struct progress_dispatch_s *dispatch; npth_t mytid = npth_self (); (void)data; for (dispatch = progress_dispatch_list; dispatch; dispatch = dispatch->next) if (dispatch->ctrl && dispatch->tid == mytid) break; if (dispatch && dispatch->cb) dispatch->cb (dispatch->ctrl, what, printchar, current, total); /* Libgcrypt < 1.8 does not know about nPth and thus when it reads * from /dev/random this will block the process. To mitigate this * problem we take a short nap when Libgcrypt tells us that it needs * more entropy. This way other threads have chance to run. */ #if GCRYPT_VERSION_NUMBER < 0x010800 /* 1.8.0 */ if (what && !strcmp (what, "need_entropy")) npth_usleep (100000); /* 100ms */ #endif } That last part with npth_usleep was added between 2.1.15 and 2.1.17. Since this is conditionally compiled if libgcrypt is older than 1.8.0, the straightforward fix would be recompiling gnupg against libgcrypt 1.8.0 or later… unfortunately that version doesn't seem to exist yet. The weird thing is, that comment about libgcrypt reading /dev/random is not true. Stracing the agent reveals it's reading from /dev/urandom and using the new getrandom(2) syscall, without blocking. It does however send many need_entropy messages, causing npth_usleep to block. Deleting those lines fixes the issue. I should mention that npth seems to be some kind of cooperative multitasking library, and npth_usleep is probably its way to yield, so it might be better to just significantly reduce that delay, just in case libgcrypt decides to block some day. (1ms is not noticeable)
gnupg 2.1.16 blocks waiting for entropy
1,367,338,736,000
So.. if there is a bad block on the HDD, what can survive better? not using FDE (full disc encryption) using FDE - since the whole disk has "1 partition" - the encrypted one, isn't it more likely to loose all data if there is a HDD error, ex.: bad block?
No, I mean yes, I mean... a little bit of both. If a block is bad, the data of that block is gone. Whether the block contained encrypted data or not, is not relevant at that point. It doesn't make a difference. Of course there are special cases. If your encryption has a metadata header, such as LUKS does, and the bad block happens to be one that holds your encryption key, then that single bad block can render the entire disk unreadable and the entire data lost. If the machine is still running and has the container open, don't reboot without writing down the key first... (e.g. dmsetup table --showkeys). But the same can happen to you in an unencrypted scenario. If critical filesystem metadata goes bad, your files are probably gone. And rescue tools like PhotoRec that try to make sense of remaining clear text data may not be able to yield satisfactory results (depending on whether you stored files in a known format, fragmentation and other things). In the end no matter what you do, you always need backups. After all, a HDD may just as well die completely rather than have just a bad block here and there.
Does using full-disk encryption affect the probability of losing data in case of storage errors?
1,367,338,736,000
I know the typical encryption types for Linux are $1$, $2a$, $2y$, $5$, and $6$, but I haven't found any answers for what $y$ is. I'm using the latest version of Kali Linux. The two accounts are dummy accounts made for an exercise. exam_user_1:$y$j9T$Sn7.l9zwy3VX0vbgSX1JQ0$iHN/q4Q9CPnTxm/x01joswdLKgfbexP1BKCkc13pqI6:18845:0:99999:7::: exam_user_2:$y$j9T$ylZ/f6ILdzB/AFXh3lhRI/$adutx/xXKNf5PmGLUMMfzCa4/uIlS7ZzbU/5LIiPjo3:18845:0:99999:7:::
From man 5 crypt, AVAILABLE HASHING METHODS yescrypt yescrypt is a scalable passphrase hashing scheme designed by Solar Designer, which is based on Colin Percival's scrypt. Recommended for new hashes. Prefix "$y$" Hashed passphrase format \$y\$[./A-Za-z0-9]+\$[./A-Za-z0-9]{,86}\$[./A-Za-z0-9]{43} Maximum passphrase length unlimited Hash size 256 bits Salt size up to 512 bits CPU time cost parameter 1 to 11 (logarithmic)
What's the encryption type $y$ used in /etc/passwd on Kali Linux?
1,367,338,736,000
I'm trying to use cryptdisks_start to open a LUKS device that is defined in my /etc/crypttab. Unfortunately, the command fails with the following error message: martin ~ # cryptdisks_start luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 * Starting crypto disk... * luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 (starting).. * luks-01a2e5d8-9211-40ce-b160-d3f973d1a155: the precheck for '/dev/disk/by-uuid/01a2e5d8-9211-40ce-b160-d3f973d1a155' failed: - The device /dev/disk/by-uuid/01a2e5d8-9211-40ce-b160-d3f973d1a155 contains a filesystem type crypto_LUKS. * luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 (failed)... ...fail! A rather strange error, because of course that device has to contain a crypto_LUKS filesystem! The relevant line from /etc/crypttab, as set up by GNOME Disks: luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 UUID=01a2e5d8-9211-40ce-b160-d3f973d1a155 /etc/luks-keys/luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 nofail
It doesn't work because the /etc/crypttab line is missing the option keyword luks. Changing the line to this resolved the issue: luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 UUID=01a2e5d8-9211-40ce-b160-d3f973d1a155 /etc/luks-keys/luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 luks,nofail This is due to the fact that cryptdisks_start uses the options to determine what kind of encryption is being used so that it will use the correct command to open the device. Without the luks option, cryptdisks_start will try to open the device as a plain dm-crypt device with cryptsetup create. Luckily a sanity check prevents this, although it causes a confusing error message. Apparently the Disks tool of GNOME3 writes this incorrect line to /etc/crypttab when using the unlock icon and saving the passphrase.
cryptdisks_start: precheck failed: the device contains a filesystem type crypto_LUKS
1,367,338,736,000
I wiped the disk using wipefs -a /dev/sda. I happily formatted the disk, and it seems that when I'm about to mount /dev/sda3 it says "unknown file system type crypto_LUKS". I did no encryption on this partition, so it's like the previous configuration is saved somehow. If I apparently wiped or reset the disk, how can this be possible? Do I have to open and decrypt and remove encryption on that drive first?
wipefs -a /dev/sdx only wipes magic signatures on that device, not on its partitions. So at best, it only wipes your partition table, but if you then proceed to re-create the partitions at the same offsets at before, the old data is still there. You'd have to wipe the partitions as well. wipefs -a /dev/sdx[1-9]* # wipe old partitions wipefs -a /dev/sdx # wipe the disk itself parted /dev/sdx # create new partitions wipefs -a /dev/sdx[1-9]* # wipe the new partitions, just in case # create filesystems or whatever That aside it's also entirely possible for wipefs to not wipe something if it doesn't know the signature. Or for another program to still recognize the data on the partition despite the signature being damaged. wipefs only overwrites a few magic bytes, which is reversible in most cases.
Partition still encrypted with luks after wipefs
1,367,338,736,000
I'm puzzled by the hash (ASCII) code stored under Linux (Ubuntu) /etc/shadow. Taking a hypothetical case, let password be 'test', salt be 'Zem197T4'. By running following command, $ mkpasswd -m SHA-512 test Zem197T4 A long series of ASCII characters are generated (This is actually how Linux store in the /etc/shadow) $6$Zem197T4$oCUr0iMuvRJnMqk3FFi72KWuLAcKU.ydjfMvuXAHgpzNtijJFrGv80tifR1ySJWsb4sdPJqxzCLwUFkX6FKVZ0 When using online SHA-512 generator (e.g. http://www.insidepro.com/hashes.php?lang=eng), what is generated is some hex code as below: option 1) password+salt 8d4b73598280019ef818e44eb4493c661b871bf758663d52907c762f649fe3355f698ccabb3b0c59e44f1f6db06ef4690c16a2682382617c6121925082613fe2 option 2) salt+password b0197333c018b3b26856473296fcb8637c4f58ab7f4ee2d6868919162fa6a61c8ba93824019aa158e62ccf611c829026b168fc4bf90b2e6b63c0f617198006c2 I believe these hex code should be the 'same thing' as the ascii code generated by mkpasswd. But how are they related? Hope someone could enlighten me?
On Ubuntu/Debian mkpasswd is part of the package whois and implemented in mkpasswd.c which as actually just a sophisticated wrapper around the crypt() function in glibc declared in unistd.h. crypt() takes two arguments password and salt. Password is "test" in this case, salt is prepended by "$6$" for the SHA-512 hash (see SHA-crypt) so "$6$Zem197T4" is passed to crypt(). Maybe you noticed the -R option of mkpasswd which determines the number of rounds. In the document you'll find a default of 5000 rounds. This is the first hint why the result would never be equal to the simple concatenation of salt and password, it's not hashed only once. Actually if you pass -R 5000 you get the same result. In this case "$6$rounds=5000$Zem197T4" is passed to crypt() and the implementation in glibc (which is the libc of Debian/Ubuntu) extracts the method and number of rounds from this. What happens inside crypt() is more complicated than just computing a single hash and the result is base64 encoded in the end. That's why the result you showed contains all kinds of characters after the last '$' and not only [0-9a-f] as in the typical hex string of a SHA-512 hash. The algorithm is described in detail in the already mentioned SHA-Crypt document.
SHA512 salted hash from mkpasswd doesn't match an online version
1,367,338,736,000
Zip encryption has had often a bad reputation of being weak, but some would argue that a zip file encrypted using certain algorithms (such as by using AES), together with strong password, is really safe (see: https://superuser.com/questions/145167/is-zips-encryption-really-bad ) My question is: how strong is the encryption of a zip file in Linux Mint 17.1, when one compress a file by right clicking on it in Nemo and then selecting the context "Compress..."? Does it use this same AES standard as recommended by the link above? Please assume a strong password using upper and lower case letters, numbers, symbols, 16+ digits and not a dictionary word.
File Roller (the GNOME application whose variant/fork/whatever-you-call-it you use) depends on zip. That should not be the case - according to the fileroller news page, p7zip is used to create zip archives since version 2.23.4 - see this somewhat outdated fileroller news page. It's also stated on 7-Zip's Wiki page: 7-Zip supports: The 256-bit AES cipher. Encryption can be enabled for both files and the 7z directory structure. When the directory structure is encrypted, users are required to supply a password to see the filenames contained within the archive. WinZip-developed zip file AES encryption standard is also available in 7-Zip to encrypt ZIP archives with AES 256-bit, but it does not offer filename encryption as in 7z archives. Checking a standard-encrypted zip file from fileroller on the terminal shows: 7z l -slt [myStrongFile.zip] -> Method = AES-128 Deflate Where 7-Zip's own deflate algorithm applies (which yields better compression, too), according to the Wiki. ** If you want stronger encryption, you have two options: ** use the terminal and use the higher zip encrypt security option: 7z a -p -mem=AES256 -tzip [myStrongerFile.zip] [fileToEncrypt1] [fileToEncrypt2] ... Checking the encrypted 7z file on the terminal shows: 7z l -slt [myStrongerFile.zip] -> Method = AES-256 Deflate use the 7z format and encryption with fileroller, which also supports directory folder encryption, in contrary to zip files: Checking the encrypted 7z file on the terminal shows: 7z l -slt [myStrongerFile.7z] -> Method = LZMA:3m 7zAES:19 Which means AES-256
How strong is the encryption of a zip file in Linux Mint
1,367,338,736,000
I already asked once about LUKS unlocking of multiple HDDs in Linux: LUKS and multiple hard drives. Now I would like to know how to secure store the keyfile used for the automatic unlock of the associated partitions. My plan is (if possible): Encrypt a small USB drive with LUKS that requires a passphrase Unlock it at boot as the first drive by using the passphrase Mount it to a given mount point, for instance /test (is this possible ?) Now the keyfile can be safely read: /test/keyfile Use the keyfile to unlock other drives without needing to ask password for them LuksClose the USB drive in order to assure a certain degree of safety as soon as other drives have been unlocked Automount /, /usr, /var and other mount-points as usual Can this work? Basically I store the LUKS keyfile on a password-encrypted LUKS USB drive that only asks for passphrase once, while all other drives can be unlocked without further action. I'm not sure if there is some way to make the USB drive be unlocked first, then be mounted and only then the other drives try to access the keyfile. Furthermore in what concerns automation I suppose /etc/fstab and /etc/crypttab should be accessible BEFORE the other drives can be mounted, but this is not possible if the whole / file system is LUKS encrypted. Unless there is the possibility of fully manually configure how LUKS works: LuksOpen /dev/sdc1 usb_keyfile mount /dev/mapper/usb_keyfile /keyfile (is this possible ?) LuksOpen --keyfile /keyfile/key /dev/sda1 disk1 LuksOpen --keyfile /keyfile/key /dev/sdb1 disk2 LuksClose /dev/sdc1 Basically being able to run a shell script just after the required modules have been loaded and disable automatic LUKS password prompt. Additionnal details Distribution used: Gentoo GNU/Linux (amd64) or Debian GNU/Linux (amd64) because I'd like to apply this procedure to multiple installations
Your approach looks good. Some remarks though: If you want to encrypt rootfs, you'll need to use initrd (to have some minimal unencrypted system that will process the encrypted partitions). If the USB device is removable, both initrd and kernel can be stored on the USB to heighten tamper resistance (supposing you make sure the USB won't get into unauthorized hands) - which is usually why one encrypts rootfs. Once both kernel and initrd are on a removable media, you can ensure that nobody changes the kernel (or initrd) from the running system by simply removing the media. This is of course not an option if you want to have it inside of a server, but then again the question stands whether it makes sense to have such a device at all and not to use a small partition on one of the hard-drives. If for example all drives in the machine are in RAID, one would probably want to put rootfs on the USB as well. An interesting alternative to an internally connected USB flash device could be a CompactFlash card attached to ATA interface through an adapter, by the way. Some distributions offer prepared solutions for encrypted root, some don't - but mostly it's question of putting a couple of lines into initrd script before it tries to mount the "real" root (see for example man pages for pivot_root, usually in sections 2 (syscall) and 8 (bonary), if you're not familiar with the process). remember to backup the keys and passphrases in case your USB drive dies. LUKS follows rather one-sided approach when it comes to damaging its header - once a single sector of its header (key-slot to be more precise) dies, you are unable to mount it. This is to make sure that erasing the header isn't effectively thwarted by block reallocation performed by the device itself (because that's what flash-memory based devices do a lot) - the key is spread over the whole key slot and one needs all of the data to reconstruct it - there is no redundancy. See Clemens Fruwirth's website for deeper discussion. That said, maybe a simple encrypted device on the USB would be enough (check section PLAIN MODE in man cryptsetup). Or a file encrypted with e.g. openssl enc. The former might actually be an option even for the encrypted partitions themselves.
LUKS storing keyfile in encrypted usb drive
1,367,338,736,000
My previous question produced the commands to add an encrypted swap file: # One-time setup: fallocate -l 4G /root/swapfile.crypt chmod 600 /root/swapfile.crypt # On every boot: loop=$(losetup -f) losetup ${loop} /root/swapfile.crypt cryptsetup open --type plain --key-file /dev/urandom ${loop} swapfile mkswap /dev/mapper/swapfile swapon /dev/mapper/swapfile But Arch Linux uses systemd, and I'm having trouble figuring out how to best get systemd to activate my swap file automatically. systemd.swap suggests that I should have a dev-mapper-swapfile.swap unit that looks something like: [Unit] Description=Encrypted Swap File [Swap] What=/dev/mapper/swapfile That would execute the swapon command. But I'm not sure how to execute the commands to prepare /dev/mapper/swapfile. I gather that dev-mapper-swapfile.swap should declare a dependency on some other unit, but I'm not sure what that unit should look like.
You may want to have a look at: crypttab(5) [email protected](8) systemd-cryptsetup-generator(8) Those work for encrypted volumes backed by block devices. They should also work for file backed volumes. Update: This does work for me: # Automatically generated by systemd-cryptsetup-generator [Unit] Description=Cryptography Setup for %I Documentation=man:[email protected](8) man:crypttab(5) SourcePath=/etc/crypttab Conflicts=umount.target DefaultDependencies=no BindsTo=dev-mapper-%i.device After=systemd-readahead-collect.service systemd-readahead-replay.service Before=umount.target Before=cryptsetup.target After=systemd-random-seed-load.service [Service] Type=oneshot RemainAfterExit=yes TimeoutSec=0 ExecStart=/usr/lib/systemd/systemd-cryptsetup attach 'swap2' '/swap.test' '/dev/urandom' 'swap' ExecStop=/usr/lib/systemd/systemd-cryptsetup detach 'swap2' ExecStartPost=/sbin/mkswap '/dev/mapper/swap2' Steps to get this file: Create an entry in /etc/crypttab: swap2 /swap.test /dev/urandom swap Run this command: /usr/lib/systemd/system-generators/systemd-cryptsetup-generator This creates unit files in the /tmp/ directory. Search for the generated unit file. Open it and remove the entry swap.test.device from the After= and BindsTo= directives. This is important, as there is by definition no device for the swapfile. This prevents the start of the unitfile. Copy the unitfile to /etc/systemd/system/ Activate it for your favourite target.
How do I configure systemd to activate an encrypted swap file?
1,367,338,736,000
I am using manjaro with full disk encrypt, however, the wait time at boot for decrypt is very long ( i assume because of a high difficulty setting) . How can I change encryption difficulty/ wait time of the encryption setup during install?
Too much passphrase hashing? If it's only slow because you're waiting for a lot of passphrase hashing iterations, you could add a new passphrase with a quicker --iter-time, but that could reduce security & allow faster guessing of passphrases. If you wanted to wait 1 second (1000ms) then use a command like: cryptsetup -v luksAddKey --iter-time 1000 <device> You might then have to delete the old slow passphrase (with luksKillSlot), unless it's key slot is after the new quick one (they're apparently tested in order, so might have to wait for the first slow slot to be tested before the later quick one). Or change your initial open command to specify the new quicker --key-slot number. The luksChangeKey command can combine the two steps, adding a new key then deleting the old key (even though the v1.7 man page doesn't specifically say it can use --iter-time, apparently it can): cryptsetup -v luksChangeKey --iter-time 1000 <device> How slow is it now? Test how long it takes to decrypt / open your device with: cryptsetup -v luksOpen --test-passphrase <device> Or test a specific key slot with the --key-slot option: cryptsetup -v luksOpen --test-passphrase --key-slot N <device> Using the time command might help, but also count your typing speed. You can use the luksDump command to see what the current key slot Iterations: are, this is an example of a very slow slot 0 and a very quick slot 1: Key Slot 0: ENABLED Iterations: 4663017 Salt: ...... Key material offset: 8 AF stripes: 4000 Key Slot 1: ENABLED Iterations: 1000 Salt: ...... Key material offset: 264 AF stripes: 4000 From man cryptsetup: --iter-time, -i The number of milliseconds to spend with PBKDF2 passphrase processing. This option is only relevant for LUKS operations that set or change passphrases, such as luksFormat or luksAddKey. Specifying 0 as parameter selects the compiled-in default. luksChangeKey <device> [<new key file>] Changes an existing passphrase. The passphrase to be changed must be supplied interactively or via --key-file. The new passphrase can be supplied interactively or in a file given as positional argument. If a key-slot is specified (via --key-slot), the passphrase for that key-slot must be given and the new passphrase will overwrite the specified key-slot. If no key- slot is specified and there is still a free key-slot, then the new passphrase will be put into a free key-slot before the key-slot containing the old passphrase is purged. If there is no free key-slot, then the key-slot with the old passphrase is overwritten directly. WARNING: If a key-slot is overwritten, a media failure during this operation can cause the overwrite to fail after the old passphrase has been wiped and make the LUKS container inaccessible. It's not the passphrase hashing? There's lots of reasons for a slow boot time, maybe it's unrelated to the encryption. Or if the actual encryption/decryption itself is too slow, then changing the algorithm or key size might be required, and that would require decrypting and re-encrypting everything. There are programs (or commands in newer versions) that can do it in-place, hopefully without losing anything, but having a backup would be more than an excellent idea. But in that case, it wouldn't just be a long initial wait but all reads & writes would be a little slower. You can use the cryptsetup -v benchmark command to see some speed tests, but "NOTE: This benchmark is using memory only and is only informative. You cannot directly predict real storage encryption speed from it."
How to change luks encryption difficulty on manjaro full disk encrypt
1,367,338,736,000
I decided to encrypt my root partition with LUKS+LVM. My ThinkPad setup: Samsung 830 128GB SSD 750GB HDD Core 2 Duo 2,5 GHz P9500 8GB RAM But the more I read, the less I understand about those two following subjects: 1a. The cipher I was going to use SHA1 instead of 2/512 (as some suggest), because of that quote from cryptsetup FAQ: 5.20 LUKS is broken! It uses SHA-1! No, it is not. SHA-1 is (academically) broken for finding collisions, but not for using it in a key-derivation function. And that collision vulnerability is for non-iterated use only. And you need the hash-value in verbatim. This basically means that if you already have a slot-key, and you have set the PBKDF2 iteration count to 1 (it is > 10'000 normally), you could (maybe) derive a different passphrase that gives you the the same slot-key. But if you have the slot-key, you can already unlock the key-slot and get the master key, breaking everything. So basically, this SHA-1 vulnerability allows you to open a LUKS container with high effort when you already have it open. The real problem here is people that do not understand crypto and claim things are broken just because some mechanism is used that has been broken for a specific different use. The way the mechanism is used matters very much. A hash that is broken for one use can be completely secure for other uses and here it is. Which I read as "there is no point of using anything other than SHA-1". But then some people tell me, that it's not exactly like that. So I no longer know what to think. 1b. Also, I could not find any information whether the cipher has any influence on disk read/write/seek performance once the disk is unlocked and system logged into. So does the complexity of the cipher affect only the "performance" on password entering stage, or also during normal use of the system? 2. The algorithm I have been reading on this since couple of days, but the more I read, the more confused I get. Everything I read says that AES is the fastest, and Serpent is the slowest. But not according to my laptop: $ cryptsetup benchmark Tests are approximate using memory only (no storage IO). PBKDF2-sha1 344926 iterations per second PBKDF2-sha256 198593 iterations per second PBKDF2-sha512 129007 iterations per second PBKDF2-ripemd160 271933 iterations per second PBKDF2-whirlpool 134295 iterations per second # Algorithm | Key | Encryption | Decryption aes-cbc 128b 149.8 MiB/s 147.9 MiB/s serpent-cbc 128b 51.0 MiB/s 196.4 MiB/s twofish-cbc 128b 127.6 MiB/s 152.5 MiB/s aes-cbc 256b 114.3 MiB/s 113.8 MiB/s serpent-cbc 256b 51.2 MiB/s 198.9 MiB/s twofish-cbc 256b 129.8 MiB/s 167.5 MiB/s aes-xts 256b 153.3 MiB/s 150.6 MiB/s serpent-xts 256b 176.4 MiB/s 184.1 MiB/s twofish-xts 256b 160.8 MiB/s 159.8 MiB/s aes-xts 512b 115.4 MiB/s 112.1 MiB/s serpent-xts 512b 178.6 MiB/s 184.2 MiB/s twofish-xts 512b 160.7 MiB/s 158.9 MiB/s So it appears that Serpent's not only the fastest, but on top of that it is the fastest with the most complex key. Shouldn't it be the other way around? Am I reading it wrong, or something?
1a - it really doesn't matter all that much. which ever hash you use for the key derivation function, LUKS makes sure it will be computationally expensive. It will simply loop it until 1 second real time has passed. 1b - the key derivation method has no influence on performance. the cipher itself does. cryptsetup benchmark shows you as much. 2 - AES is the fastest if your CPU is modern enough to support AES-NI instructions (hardware acceleration for AES). If you go with serpent now you may not be able to utilize the AES-NI of your next laptop. # Tests are approximate using memory only (no storage IO). PBKDF2-sha1 1165084 iterations per second PBKDF2-sha256 781353 iterations per second PBKDF2-sha512 588426 iterations per second PBKDF2-ripemd160 726160 iterations per second PBKDF2-whirlpool 261882 iterations per second # Algorithm | Key | Encryption | Decryption aes-cbc 128b 692.9 MiB/s 3091.3 MiB/s serpent-cbc 128b 94.6 MiB/s 308.6 MiB/s twofish-cbc 128b 195.2 MiB/s 378.7 MiB/s aes-cbc 256b 519.5 MiB/s 2374.0 MiB/s serpent-cbc 256b 96.5 MiB/s 311.3 MiB/s twofish-cbc 256b 197.9 MiB/s 378.0 MiB/s aes-xts 256b 2630.6 MiB/s 2714.8 MiB/s serpent-xts 256b 310.4 MiB/s 303.8 MiB/s twofish-xts 256b 367.4 MiB/s 376.6 MiB/s aes-xts 512b 2048.6 MiB/s 2076.1 MiB/s serpent-xts 512b 317.0 MiB/s 304.2 MiB/s twofish-xts 512b 368.7 MiB/s 377.0 MiB/s Keep in mind this benchmark does not use storage so you should verify these results with whatever storage and filesystem you are actually going to use.
Trying to understand LUKS encryption
1,367,338,736,000
All my partitions are encrypted (/ and /home), but the /boot partition has to remain unencrypted and is open for manipulation. I was thinking about hashing the kernel on bootup and checking the result against a stored value (generated on compile, saved on my encrypted drive) to see if someone, somehow manipulated the kernel since the last boot (maybe even physically). Is there a problem with writing such a script? Are there programs that do this already?
What you're looking for — verifying that the operating system running on the computer is one you trust — is called trusted boot. (It's one of several things that are sometimes called trusted boot). Your proposed method does not achieve this objective. Encryption does not provide data integrity or authenticity. In other words, it does not prevent an attacker from modifying the contents of your disk and replacing it by a malicious operating system. This malicious operating system could easily be programmed to show the checksum that you expect for the loaded kernel. The easiest path of attack is a man-in-the-middle where the attacker runs your normal operating system under some kind of virtual machine. The virtual machine layer transmits your input to your desired operating system and transmits output back. But it also records your keystrokes (mmmm, passwords) on the side, snoops private keys from the OS's memory and so on. In order to avoid this form of attack, you need to have a root of trust: a component of the system that you trust for a reason other than because some other component of the system says so. In other words, you have to start somewhere. Starting with hardware in your possession is a good start; you could keep your operating system on a USB key that doesn't leave your sight, and plug that only in hardware that you have sufficient confidence in (hardware can have malware!). Mind, if you're willing to trust the computer, you might trust its hard disk too. There is a technical solution to bridge the gap between trusting a small chip and trusting a whole desktop or laptop computer. Some PCs have a TPM (trusted platform module) which can, amongst others, verify that only a known operating system can be booted. Trusted Grub supports TPMs, so with a TPM plus Trusted Grub, you can have the assurance that the kernel you're running is one that you have approved. Note that the adoption of the TPM can work for or against you. It all hinges on who has the keys. If you have the private key for your TPM, then you can control exactly what runs on your computer. If only the manufacturer has the private key, it's a way to turn a general-purpose platform into a locked-in appliance.
Signing/Checksumming the kernel to prevent/detect manipulation
1,367,338,736,000
Basically, I have an email account I can access as POP3 or IMAP. I want to take all incoming emails, encrypt them, and then forward the encrypted version to my gmail account (so I can see the subject/notifications on my phone/gmail account; and possibly decrypt the message with a passphrase -- though this last step doesn't need to be implemented initially). I probably could write a python script to do this, but using the proper linux tools seems like a better route. I have postfix (in a satelite configuration) already set up to send outgoing mail. What's the easiest way to read POP3/IMAP on a linux box and get it to gpg encrypt the email's body and attachments (not subject headers) with my public key, and forward it to my gmail acct? (For the record; its against work's policy (partially for compliance with US HIPAA law) for me to send unencrypted versions of my email to my phone; as there's the potential for someone to deliberately (or inadvertantly) email protected data to my phone. Work considers GPG to be secure.)
I just saw the other response and guess I never wrote up the solution I actually implemented. It turns out that python imaplib is straightforward and I wrote a very quick script. Barring a few changes (e.g., anonymizing my various USERNAMEs, EMAILPASSWORD, WORKDOMAINNAME, MYGPGKEYID). I also don't just send encrypted it; but prepend the subject with the username of the sender and put some of the header stuff before the GPG (in case I'm reading it on my phone and can't decrypt). #!/usr/bin/python import imaplib import email from datetime import datetime,timedelta import shelve from subprocess import Popen, PIPE def piped_call(command1, arg1_list, command2, arg2_list): """ if arg1_tuple = (a10, a11, a12); arg2_tuple is (a20, a21) This executes "command1 a10 a11 a12 | command2 a20 a21 a22" """ if type(arg1_list) not in (list, tuple): arg1_list = [arg1_list,] if type(arg2_list) not in (list, tuple): arg2_list = [arg2_list,] p1 = Popen([command1,]+list(arg1_list), stdout=PIPE) p2 = Popen([command2,]+list(arg2_list), stdin=p1.stdout, stdout=PIPE) p1.stdout.close() return p2.communicate()[0] shlf = shelve.open('/home/USERNAME/mail/mail.shlf') # This shelf (a persistent python dictionary written to file) has as its key # the IMAP message ids of all emails that have been processed by this script. # Every time the script runs, I fetch all emails from the current day # (except from midnight to 1am, where I fetch all emails since yesterday) # and then send all emails that haven't been sent previously # by checking message ids against the python shelf. M = imaplib.IMAP4_SSL(host='imap.WORKDOMAINNAME.com', port=993) M.login('EMAILUSERNAME', 'EMAILPASSWORD') M.select() dt = datetime.now() - timedelta(0,5*60*60) # Only search for messages since the day of an hour earlier. # This way messages from yesterday don't get lost at midnight; as well as limiting the number of messages to process through to just todays. typ, uid_data = M.uid('search', None, '(SINCE %s)' % dt.strftime('%d-%b-%Y')) for num in uid_data[0].split(): typ, data = M.uid('fetch', num, '(RFC822)') e = email.message_from_string(data[0][1]) print 'Message %s\n%s\n' % (num, e['subject']) if num not in shlf: sender_email = e['return-path'] for s in ('<', '>', '@WORKDOMAINNAME.com'): sender_email = sender_email.replace(s,'') subject = "%s: %s" % (sender_email, e['Subject']) body = ("From: %s\n" "To: %s\n" "Cc: %s\n" "Subject: %s\n\n" % (e['From'], e['To'], e['Cc'], e['subject'])) payload = e.get_payload() if type(payload) in (list, tuple): payload = str(payload[0]) else: payload = str(payload) encrypted_payload = piped_call('echo', (payload,), 'gpg', ('-e', '-a', '-r', 'MYGPGKEYID')) body += encrypted_payload piped_call('echo', (body,), 'mail', ['[email protected]', '-s', subject]) shlf[num] = datetime.now() M.close() M.logout() I then added the following lines to my crontab (the script above is named mail.py inside a directory called mail), so it will run every 5 minutes during the normal hours on weekdays (M-F 8-7pm) and less frequently at other hours. (crontab -e) # Every 5 minutes, M-F from 8am - 7pm. */5 8-19 * * 1-5 cd /home/USERNAME/mail && ./mail.py >> /home/USERNAME/mail/mail.log 2>&1 # Every 30 minutes, Sat&Sun from 8am-7pm 0,30 8-19 * * 6,7 cd /home/USERNAME/mail && ./mail.py >> /home/USERNAME/mail/mail.log 2>&1 # Every 30 minutes, M-F 8pm-2am; (no emails 2am-8am) 0,30 0-2,20-23 * * 1-5 cd /home/USERNAME/mail && ./mail.py >> /home/USERNAME/mail/mail.log 2>&1 # Every 60 minutes, Sat&Sun hours 8pm-2am; (no emails 2am-8am) 0 0-2,20-23 * * 6-7 cd /home/USERNAME/mail && ./mail.py >> /home/USERNAME/mail/mail.log 2>&1
Receive Pop/IMAP email and then forward as encrypted to gmail
1,367,338,736,000
I'm askin myself, is there any software who can encrypt my whole hard drive with Linux Mint 17.3 on it AFTER the installation? Like TrueCrypt for Windows?! If not and I've to reinstall everthing is there any possibility to safe all my datas (including the installed programs) to restore it after an successful installation of an fully encrypted OS? Maybe with this tool (included in Linux Mint): http://www.crmk.de/mintbackuptool.jpg ???
If you want the entire hard drive encrypted, even the Linux Mint system partitions, swap, your home, the whole works, then I suspect the easiest would be to: backup your data (the Mint Backup Tool you linked an image to should work, but double-check for files you want backed up that aren't in your home) reinstall with encryption using the installer (I'm pretty sure it supports system encryption) then restore your data (home, reinstall programs) OR Just encrypt your home folder now with ecryptfs-migrate-home but be sure & read it's man page & should heed it's warnings: WARNING: Make a complete backup copy of the non-encrypted data to another system or external media. This script is dangerous and in case of an error, could result in data lost, or lock USER out of the system! ... After a successful migration, the USER really must run ecryptfs-unwrap-passphrase(1) or zescrow(1) and record their randomly generated mount passphrase. And ecryptfs-setup-swap would encrypt your swap too, if interested.
Is there any way to fully encrypt my hard-drive AFTER an installation of Linux Mint?
1,367,338,736,000
I'm trying to recover my files from a now broken Antergos install, and have run into trouble because the user/non-boot partition is encrypted with LUKS encryption. I'm booting from an Ubuntu 18.04 bootable USB drive so I can backup the directories where I had data I wanted, and didn't realize it was encrypted until I went to go view the partition in the file explorer, and it didn't show up. It was suggested to me that it may not be mounted, and after looking at GParted it's clear that that was the problem, and it seems like it wasn't mounted because it's encrypted (prior experiences with backing up before reinstalling or switching distros never involved any problems with the partition I was recovering files from not being mounted). As some additional information: I have the password that was required in order to boot and get to the greeter. I'm operating under the assumption that that's my encryption key, but I may be mistaken, I'm rather out of my depth here. The partition/volume in question is sda3 (not sure which is the correct term) and in addition to being encrypted it uses LVM. I'm not sure how that impacts things, but the impression I've gotten from the reading I've been doing to try and resolve this seems to suggest that it matters I initially tried to mount the partition via the command line trying two different methods, and both returned different errors. Unfortunately I let my computer die because I walked away from my computer for a while before trying again, and I can't find any of the pages I was referencing and attempting to follow along with, or commands I tried, or errors I got back. The error I can provide is that when I tried to follow this guide the command: "cryptsetup luksOpen /dev/sda3/ recoverytarget" returned: "Device /dev/sda3/ doesn't exist or access denied." I assume that I need to mount the partition before I can de-encrypt it, but again I may be mistaken it's been a while since I worked on any of my Linux machines, and I'm not the most technically competent or linux experienced person in the world, so please forgive any instances where it's painfully clear I don't understand something EDIT/UPDATE: The error I was getting was because I wasn't running the command with sudo in front, so now I officially feel stupid, but I'm now running into a different problem where "sudo mkdir /mnt/recoverytarget && mount /dev/mapper/recoverytarget /mnt/recoverytarget" returns: "mount: only root can do that"
To recover your files you will first need to open your LUKS container. This will make your LVM logical volumes accessible. Then, you can mount the appropriate logical volume to gain access to the files. I'll assume that once you have access to the files you'll know what to do. Opening the LUKS container To open the LUKS container run: sudo cryptsetup open /dev/sda3 luksrecoverytarget --type luks Assuming you enter a valid passphrase, you'll now have the block device /dev/mapper/luksrecoverytarget; it's actually a symlink, but you can ignore that detail. That block device contains your LVM volume group. Next you need to determine which logical volume to mount. Find the correct logical volume Upon opening the LUKS container your OS should have scanned for LVM logical volumes. If not you can run sudo vgscan to get things synced up. To get a list of logical volumes run sudo lvdisplay. You'll see a list of one or more logical volumes. Hopefully you'll be able to tell which one you want to recover by looking at the LV Path. Mount the logical volume Once you know which logical volume to mount run: sudo mkdir /mnt/recoverytarget sudo mount LV_PATH_GOES_HERE /mnt/recoverytarget Now you may do as you wish with the files. Clean up Once you're done, you should unmount the filesystem and close the LUKS container: sudo umount /mnt/recoverytarget sudo cryptsetup close luksrecoverytarget
How to mount and de-encrypt a LUKS encrypted partition to recover files [closed]
1,367,338,736,000
I'm looking for a solution to fully encrypt my dual-boot SSD drive (it's still new and empty, and I want to set up encryption before I put anything on it). While there's a lot of chaos on the web regarding that question, it appears that TrueCrypt might be able to do this, although I might need its boot loader on an extra boot disk. From what I'm reading, some Linux tools (including some modified GRUB2) might also be able to do that. However, I have my doubts, and no article I read really went in deep enough to answer a basic question: if the whole disk is encrypted, and some pre-boot tool asks the user for a key to decrypt it, doesn't that mean this tool has to run beneath the OS that's going to boot? In other words, are there tools that leave the OS unaware of the fact that the disks it sees are actually encrypted? If there's no such tool, doesn't that mean the decryption tool somehow has to pass decryption information to the OS on boot? I can imagine that this would be hard to do cross-platform.
If the whole disk is encrypted, and some pre-boot tool asks the user for a key to decrypt it, doesn't that mean this tool has to run beneath the OS that's going to boot? Yes, pretty much. Hardware-based full disk encryption does this: the encryption is handled entirely by the device (hard disk/flash) or possibly in a controller along the chain leading to the physical device(s), and is not "visible" to the OS. With this, the OS does I/O exactly like it would if it was dealing with a plain, unencrypted device, the magic happens in hardware (and/or firmware - "below" the OS in any case). If there's no such tool, doesn't that mean the decryption tool somehow has to pass decryption information to the OS on boot? There would have to be some form of information transfer indeed, if the encryption cannot be done "underneath" the OS (either as above, or possibly using virtualization techniques – but then you sort of have two (or more) OSes running). And yes that means cross-OS is hard. You'll also need the boostrap code (bootloader at the very least) to be un-encrypted if you don't have hardware/firmware assistance. The Wikipedia disk encryption article has more about this.
How does pre-boot authentication with disk encryption work technically?
1,367,338,736,000
On my Debian-Testing-System, I want to completely conceal the home folders. That means, I not only want the data to be encrypted, but I also want to preclude determining any (or most) information from the encrypted data. For instance, also file names should be encrypted. But not being an expert for data protection, maybe also other file/folder attributes need to be encrypted to grant privacy. I considered ecryptfs to achieve this (Package ecryptfs-utils) However, is this the right choice for my needs? I also would appreciate links to step-by-step instructions on the implementation of encrypted home-folders in Debian very much! [edit] I do a fresh install, therefore it's not necessary to migrate a previously unencrypted home folder.
Ecryptfs stores each encrypted file in one file (the lower file, in ecryptfs terminology). The directory structure of the lower files mirrors that of the payload files, although the file names are encrypted. The metadata (modification times, in particular) of the lower files also reveals that of the payload files. The size of the lower file is slightly larger than the size of the payload (with a fixed overhead for Ecryptfs's metadata)¹. If you're storing your own work, where the attacker would already know roughly what kinds of data you have (“I already know this is a source code tree, and I know these are spreadsheets, what I want to know is !”), none of that is a problem. But if you're storing directory trees that may be identified by their layout (directory structure, approximate sizes, dates), then Ecryptfs is not the right tool for you. Use encryption at the block device level. Linux provides this with dm-crypt. You can encrypt either the whole disk (except for a small area for the bootloader), or encrypt /home or some other partition. If you don't encrypt the whole disk, keep in mind that confidential information might end up in other places, especially the swap space (if you have any encrypted data anywhere, you should encrypt your swap). Note that if you go for whole-disk encryption, your computer will not be able to boot unattended, you will have to type your passphrase at the keyboard. Since the whole block device is encrypted, the location of file content and metadata cannot be detected by an attacker who steals the disk. Apart from a header at the beginning of the encrypted area, the content is indistinguishable from random noise. An attacker could derive some information from seeing multiple snapshots of the encrypted data and studying how various sectors evolve over time, but even with this it would be hard to find out anything interesting, and this doesn't apply if you stop modifying the data after the attacker has seen the ciphertext (as in the case of a disk theft). Many distributions offer the possibility to create a dmcrypt volume or encrypt the whole disk at install time. You may have to select the “advanced” or “server” installation image as opposed to the “desktop” or “basic” image. The tool to manipulate dm-crypt volumes is cryptsetup. To create a dmcrypt volume, create a partition /dev/sdz9, say, then run cryptsetup luksFormat /dev/sdz9. You'll need to add the volume to /etc/crypttab; use cryptsetup luksOpen to activate the volume on the spot, or cryptmount -a after you've set up /etc/crypttab. Dm-crypt is only a cipher layer, so you'll need to make a filesystem on the encrypted volume. Install Backtrack 5 r2 into running LUKS setup installed with ubuntu has a tutorial on setting up dm-crypt entirely manually. ¹ Experimentally, with default settings, the lower file size is the payload file size, rounded up to a multiple of 4kB, plus an 8kB overhead.
conceal home folder completely - is ecryptfs the right choice?
1,367,338,736,000
Does anyone have a working implementation using keyfiles, preferably on SD Card, instead of a prompt for ZFS? I know how to do this with linux LVM/LUKS. In my opinion the FreeBSD full disk encryption solutions are WAY more secure, but I would really like to use keyfiles instead of getting prompted during boot. I can't find a way to do it with google-magic.
Update from January 2020 This question was answered in 2011, and the answer I gave pertains specifically to contemporary Solaris 11 behavior. This does not apply to OpenZFS, illumos, or ZFS on Linux. That being said, the original answer remains, for posterity. You have to create your key first. ZFS supports two types of file based keys. Hex, and raw. For this you can use openssl to generate the key. openssl rand -out /media/stick/key 16 The 16 creates a 16-byte (i.e., 128-bit) key. For a 192-bit or 256-bit key use 24 or 32 respectively. Then create your dataset as you normally would, specifying the key. zfs create -o encryption=on -o keysource=raw,file:///media/stick/key rpool/encrypted You can also use the -hex flag to openssl rand and keysource=hex for a human readable hex value in the file.
How to use keyfiles,for ZFS whole disk encryption?
1,367,338,736,000
Notice: the very same vulnerability has been discussed in this question, but the different setting of the problem (in my case I don't need to store the passphrase) allows for a different solution (i.e. using file descriptors instead of saving the passphrase in a file, see ilkkachu's answer). Suppose I have a symmetrically encrypted file my_file (with gpg 1.x), in which I store some confidential data, and I want to edit it using the following script: read -e -s -p "Enter passphrase: " my_passphrase gpg --passphrase $my_passphrase --decrypt $my_file | stream_editing_command | gpg --yes --output $my_file --passphrase $my_passphrase --symmetric unset my_passphrase Where stream_editing_command substitutes/appends something to the stream. My question: is this safe? Will the variable $my_passphrase and/or the decrypted output be visible/accessible in some way? If it isn't safe, how should I modify the script?
gpg --passphrase $my_passphrase My question: is this safe? Will the variable $my_passphrase and/or the decrypted output be visible/accessible in some way? No, that's not really considered safe. The passphrase will be visible in the output of ps, just like all other running processes' command lines. The data itself will not be visible, the pipe is not accessible to other users. The man page for gpg has this to say about --passphrase: --passphrase string Use string as the passphrase. This can only be used if only one passphrase is supplied. Obviously, this is of very questionable security on a multi-user system. Don't use this option if you can avoid it. Of course, if you have no other users on the system and trust none of your services have been compromised there should be no-one looking at the process list. But in any case, you could instead use --passphrase-fd and have the shell redirect the passphrase to the program. Using here-strings: #!/bin/bash read -e -s -p "Enter passphrase: " my_passphrase echo # 'read -s' doesn't print a newline, so do it here gpg --passphrase-fd 3 3<<< "$my_passphrase" --decrypt "$my_file" | stream_editing_command | gpg --yes --output "$my_file" --passphrase-fd 3 3<<< "$my_passphrase" --symmetric Note that that only works if the second gpg doesn't truncate the output file before getting the full input. Otherwise the first gpg might not get to read the file before it's truncated. To avoid using the command line, you could also store the passphrase in a file, and then use --passphrase-file. But you'd then need to be careful about setting up the access permissions of the file, to remove it afterwards, and to choose a proper location for it so that the passphrase doesn't get actually stored on persistent storage.
Security of bash script involving gpg symmetric encryption
1,367,338,736,000
I am working on our Debian server on which we have a Raid drive encrypted with 2 devices. I did this around 1.5 years back and have never rebooted since. Now, we want to reboot for some reasons, but I have to make sure that the password I have is the correct one, or we will be stuck. How can we verify the password for an encrypted-raid? Thank you. Raid details : mdadm --detail /dev/md0 /dev/md0: Version : 1.2 Creation Time : Thu Feb 11 14:43:40 2016 Raid Level : raid1 Array Size : 1953382336 (1862.89 GiB 2000.26 GB) Used Dev Size : 1953382336 (1862.89 GiB 2000.26 GB) Raid Devices : 2 Total Devices : 2 Persistence : Superblock is persistent Update Time : Fri Mar 10 10:37:42 2017 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Name : HOSTNAME:0 (local to host HOSTNAME) UUID : 5c450558:44a2b1e9:83cb4361:9c74df8e Events : 49 Number Major Minor RaidDevice State 0 8 1 0 active sync /dev/sda1 1 8 17 1 active sync /dev/sdb1 Thank you. Update dmsetup table --showkeys CryptVol: 0 Large_Number crypt aes-cbc-essiv:sha256 RANDOM_TEXT 0 253:0 4096 RaidVG-LVMVol: 0 Large_Number linear 9:0 2048
mdadm does not encrypt, so what did you use? LUKS? With LUKS you can just see if cryptsetup luksAddKey /dev/md0 or similar will accept your password. Otherwise, if the container is still open, do a dmsetup table --showkeys that gives you all the parameters and master key which allows you to circumvent LUKS... I guess the correct way to test is cryptsetup --test-passphrase luksOpen /dev/luksdevice --test-passphrase Do not activate device, just verify passphrase. This option is only relevant for open action (the device mapping name is not mandatory if this option is used). But I usually just use luksAddKey ;) who knows, maybe you actually do want to add another backup passphrase in case you forget one of them. Or add the same passphrase in two different keyboard layouts (if you do not use US keyboard by default).
Debian : Verify disk encryption password for already mounted system
1,367,338,736,000
Encryption/decryption is often the main bottleneck when accessing an encrypted volume. Would using a filesystem with a fast transparent compression (such as BTRFS + LZO) help? The idea is that there would be less data to encrypt, and if the compression is significantly faster than the encryption algorithm, the overall processing time would be less. Update: As Mat pointed out, it depends on the compressibility of the actual data. Of course, I assume that its compressible, like source code or documents. Of course it has no meaning using it for media files (but I guess it won't hurt too much, as BTRFS tries to detect incompressible files.) Since testing this idea is a very time consuming process, I'm asking if somebody has already some experience with this. I tested just a very simple setup, and it seems to show a difference: $ touch BIG_EMPTY $ chattr +c BIG_EMPTY $ sync ; time ( dd if=/dev/zero of=BIG_EMPTY bs=$(( 1024*1024 )) count=1024 ; sync ) ... real 0m26.748s user 0m0.008s sys 0m2.632s $ touch BIG_EMPTY-n $ sync ; time ( dd if=/dev/zero of=BIG_EMPTY-n bs=$(( 1024*1024 )) count=1024 ; sync ) ... real 1m31.882s user 0m0.004s sys 0m2.916s
I did a small benchmark. It only tests writes though. Test data is a Linux kernel source tree (linux-3.8), already unpacked into memory (/dev/shm/ tmpfs), so there should be as little influence as possible from the data source. I used compressible data for this test since compression with non-compressible files is nonsense regardless of encryption. Using btrfs filesystem on a 4GiB LVM volume, on LUKS [aes, xts-plain, sha256], on RAID-5 over 3 disks with 64kb chunksize. CPU is a Intel E8400 2x3Ghz without AES-NI. Kernel is 3.8.2 x86_64. The script: #!/bin/bash PARTITION="/dev/lvm/btrfs" MOUNTPOINT="/mnt/btrfs" umount "$MOUNTPOINT" >& /dev/null for method in no lzo zlib do for iter in {1..3} do echo Prepare compress="$method", iter "$iter" mkfs.btrfs "$PARTITION" >& /dev/null mount -o compress="$method",compress-force="$method" "$PARTITION" "$MOUNTPOINT" sync time (cp -a /dev/shm/linux-3.8 "$MOUNTPOINT"/linux-3.8 ; umount "$MOUNTPOINT") echo Done compress="$method", iter "$iter" done done So in each iteration, it makes a fresh filesystem, and measures the time it takes to copy the linux kernel source from memory and umount. So it's a pure write-test, zero reads. The results: Prepare compress=no, iter 1 real 0m12.790s user 0m0.127s sys 0m2.033s Done compress=no, iter 1 Prepare compress=no, iter 2 real 0m15.314s user 0m0.132s sys 0m2.027s Done compress=no, iter 2 Prepare compress=no, iter 3 real 0m14.764s user 0m0.130s sys 0m2.039s Done compress=no, iter 3 Prepare compress=lzo, iter 1 real 0m11.611s user 0m0.146s sys 0m1.890s Done compress=lzo, iter 1 Prepare compress=lzo, iter 2 real 0m11.764s user 0m0.127s sys 0m1.928s Done compress=lzo, iter 2 Prepare compress=lzo, iter 3 real 0m12.065s user 0m0.132s sys 0m1.897s Done compress=lzo, iter 3 Prepare compress=zlib, iter 1 real 0m16.492s user 0m0.116s sys 0m1.886s Done compress=zlib, iter 1 Prepare compress=zlib, iter 2 real 0m16.937s user 0m0.144s sys 0m1.871s Done compress=zlib, iter 2 Prepare compress=zlib, iter 3 real 0m15.954s user 0m0.124s sys 0m1.889s Done compress=zlib, iter 3 With zlib it's a lot slower, with lzo a bit faster, and in general, not worth the bother (difference is too small for my taste, considering I used easy-to-compress data for this test). I'd make a read test also but it's more complicated as you have to deal with caching.
Will using a compressed filesystem over an encrypted volume improve performance?
1,413,031,625,000
Debian Jessie, XFCE 4.10, KeePass2, IceDove (with Enigmail).. I'm using KeePass2 generated passwords for my gpg private key, to de/encrypt mails. Icedove is my client which uses the enigmail. As soon as I want to de/encrypt a mail pinentry (pinentry-gtk2) pops up and I can't paste into the password field, nor can I move it - thus I'd like to have KeePass2 auto-type my long-ass password for me. Which does not work with the keyboard shortcut (working for anything else), but with a right-click in the KeePass2 entry for 'perform auto-type'. this is slowly driving me nuts.. I've now read a ton of forum discussions - where none were really helpful and tried to alter my gpg-agent settings to use pinentry-curses. I even removed pinentry-gtk2 which rendered icedove completly incapable of de/encryption. Any suggestions to make the auto-type feature or paste working in the pinentry window. Or an alternative pinentry?
In Keepass2, "Add Entry," and set "Title" to "GPG." Move from "Entry" tab to "Auto-Type" tab. Select "Override default sequence" and set to "{PASSWORD}". Before you send email, open Keepass2 with Keepass2 password. Ask IceDove with Enigmail to "Send" and pinentry should appear (locking keyboard, preventing "Ctrl+V" (or any other keyboard shortcut you normally use to perform auto-type), preventing switch windows "Alt+Tab", etc.). Use mouse to highlight "GPG" entry in Keepass2 and click "Perform Auto-Type" icon in Keepass2 (left of "Find" icon and underneath "Help" menu). As the keyboard "focus" was last on the pinentry text input box, Keepass2 will now start typing your long password for you. Use mouse to click "OK" on pinentry. Done! For more details on "Auto-Type" (http://keepass.info/help/base/autotype.html).
Usage of pinentry with keepass2 for gpg mail encryption
1,413,031,625,000
I'm finding a lot of conflicting information out there, and as of yet haven't found anyone trying to pull together all of the components that I'm trying to do, so I'm hoping someone who understands SSD, encrypted LVMs and so on can stop by and help out. Basically, my system is a laptop with: /dev/sda: 32 GB SSD /dev/sdb: 256 GB SSD /dev/sdc: 1000 GB HD Generally my Linux installs consist of three partitions: ~50 mb /boot large /home ~30 gb "everything else" So effectively I'd like /dev/sda1 -> /boot /dev/sda2 -> / /dev/sdb1 -> /home /dev/sdc1 -> /swap /dev/sdc2 -> /mnt/storage The catch is I'd like to encrypt all of this (except for /boot and /mnt/storage which can stay unencrypted). I've read that when encrypting SSDs there can be issues with things like TRIM, and that ideally I'd want to use EXT4 with some particular options set, and that I must be very careful with partition alignment, and some just claim that encrypted LVMs really don't play well with SSDs and I should just use EncFS or eCryptfs (although people seem unclear and/or polarized on whether these should be used to encrypt "mount-at-boot" partitions like / and /home). Is there any canonical information on this?
I'm running btrfs on top of dm-crypt for a while now. Since btrfs is a multi-device capable and dynamic (grow, shrink etc) filesystem, I don't really need the LVM layer for my purposes. Other than that, use a recent enough dm-crypt that has --allow-discards capability, 3.1+ kernel and a filesystem that also allows discards (btrfs, ext*, ...). Some stuff to read through doing all this: https://code.google.com/p/cryptsetup/wiki/Cryptsetup140 (--allow-discards) http://thread.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/4075/ http://asalor.blogspot.com/2011/08/trim-dm-crypt-problems.html (Milan Broz, dm-crypt developer) I'll update with more links over time as I find them from my bookmark abyss :> I have not benchmarked my setup particularly much. For me it's behaving more than adequate in performance i.e. still worlds ahead of HDD. I don't know for now exactly what state my SSD is in and whether the multi-layer discard system is really working 100%. What's important rather is I have enough performance with enough of a security model to fend off the higher-probability issues, such as , forgetting the device, device being stolen by random people, etc. So finding out exactly how much my SSD lifespan has possibly shortened, or performance slowed because of the discard system not working 100% correctly for TRIM, or how much dm-crypt discards weaken its inherent security - I have not been able to gather information to warrant giving these questions a high priority. One of the reasons I'm writing this answer is perhaps I'm wrong too much and putting this out here is currently the optimal way for me to try to find out.
LVM + LUKS + SSD + Gentoo -- making it all work together
1,413,031,625,000
I'm considering purchasing a 850 Evo but I'm unsure as to the security of the encryption, especially on Linux. My research has shown that bitlocker can be used on windows instead of the insecure ATA password, but is there a similar solution for Linux?
If you have the AES-NI instructions set in your CPU, then it is also hardware accelerated. Also I don't see a difference between BitLocker and LUKS. It's a similar approach but at least LUKS is open source, so I tend to trust that better. And I would trust more LUKS than the OPAL hw standard found in some HDD/SSD. At least it is better auditable. If the Samsung SSD is OPAL compliant and your BIOS/EFI supports it, then it is transparent to Linux: the "decryption" happens before the boot loader is called. My work laptop as an OPAL HDD and all I had to do is first boot from the HDD once to unlock it, stick the USB installation stick and reboot, then proceed with the installation from the stick. Note: call me paranoid, but even though this HDD was encrypted using OPAL , I still used LUKS to encrypt the Linux partition. Our IT is taking care of the Windows part, I take care of the Linux one and I don't want it to be messed up. I'm lucky that my employer allows that though!
Samsung 850 Evo SSD Hardware Encryption
1,413,031,625,000
(This is not about restricting client access, for which ext3 permissions do the trick) I'd like to encrypt the data on my NAS drive (Buffalo LinkStation Pro with SSH access enabled, if that matters) in a user-friendly way. Currently, a truecrypt container has to be manually mounted via SSH and also unmounted again (unless you solve my timeout question). Using a passwordless (but EFS encrypted) SSH key this is reduced to two PuTTY desktop shortcuts and entering the truecrypt password (until simplified further) for mounting. However, the ideal solution would be transparent. I first thought about trying to somehow have the share allow for EFS encryption, but that would probably involve more work and EFS for multiple users without an Active Directory server seems to be troublesome. But now my idea is an automated mount of e.g. an EncFS encrypted directory triggered automatically by a samba access from authorized users (using Windows clients). How can that be achieved? (Bonus points for displaying a honeypot share for unauthorized users...)
I'm seeing a sketch of a solution using Samba "logon scripts" - client-side code that runs after a samba login - but a complete solution needs to complete the sketch with details. Also related are "preexec scripts" - server-side code that runs during a samba login. Referencing the smb.conf man page logon script (G) This parameter specifies the batch file (.bat) or NT command file (.cmd) to be downloaded and run on a machine when a user successfully logs in. The file must contain the DOS style CR/LF line endings. Using a DOS-style editor to create the file is recommended. The script must be a relative path to the [netlogon] service. If the [netlogon] service specifies a path of /usr/local/samba/netlogon, and logon script = STARTUP.BAT, then the file that will be downloaded is: /usr/local/samba/netlogon/STARTUP.BAT The contents of the batch file are entirely your choice. A suggested command would be to add NET TIME \SERVER /SET /YES, to force every machine to synchronize clocks with the same time server. Another use would be to add NET USE U: \SERVER\UTILS for commonly used utilities, or NET USE Q: \\SERVER\ISO9001_QA for example. Note that it is particularly important not to allow write access to the [netlogon] share, or to grant users write permission on the batch files in a secure environment, as this would allow the batch files to be arbitrarily modified and security to be breached. This option takes the standard substitutions, allowing you to have separate logon scripts for each user or machine. and also preexec (S) This option specifies a command to be run whenever the service is connected to. It takes the usual substitutions. An interesting example is to send the users a welcome message every time they log in. Maybe a message of the day? Here is an example: preexec = csh -c 'echo \"Welcome to %S!\" | /usr/local/samba/bin/smbclient -M %m -I %I' & In your case, though, you really want logon scripts (unencrypted form is mounted on the client), so a solution sketch might involve: ensure that each computer has a EncFS equivalent installed write a logon script (.bat format) that calls encfs on the client and prompts the user for logon. The encfs command thus mounts the unencrypted form locally, with the remote store remaining encrypted. configure smb.conf so that the relevant users run the logon script. e.g. something like logon script = runencfs.bat For bonus points, your logon script might automate / prompt installation of Encfs (from the samba share) and only run the mount if it's installed! Client-side scripts, though, are bound to give you headaches because of the cmd language, ensuring installation of encfs, and working around windows gotchas, like Windows 8.1 and up not running the logon scripts till five minutes later unless otherwise configured.
How to set up an encrypted directory to be mounted only during samba access?
1,413,031,625,000
Consider this Shadow string $y$j9T$PaFEMV0mbpeadmHDv0Lp31$G/LliR3MqgdjEBcFC1E.s/3vlRofsZ0Wn5JyZHXAol5 There are 4 parts id : y (yescrypt) param : j9T salt : PaFEMV0mbpeadmHDv0Lp31 hash : G/LliR3MqgdjEBcFC1E.s/3vlRofsZ0Wn5JyZHXAol5 Q: What does j9T in param field mean? Are there other options in this field? Where can we find official documentation? I've seen this question; The format of encrypted password in /etc/shadow, however, there is no explanation there.
Disclaimer Below are my own findings and the way I interpreted them without having an expert understanding of cryptography and the concepts involved. Signatures Notably, as the yescrypt CHANGES file on the OpenWall GitHub states about the Changes made between 0.8.1 (2015/10/25) and 1.0.0 (2018/03/09), yescrypt has two signatures: $7$ - classic scrypt hashes, not very compact fixed-length encoding $y$ - native yescrypt and classic scrypt hashes, new extremely compact variable-length encoding This extremely compact variable-length encoding is what introduces much but not all of the complexity that the end of the second-to-last paragraph in this UNIX StackExchange answer talks about. Parameters For a simple description of the parameters, the BitcoinWiki Yescrypt parameters section can be helpful: Parameter Description password password to hash salt salt to use flags flags to toggle features N increasing N increases running time and memory use r increasing R increases the size of blocks operated on by the algorithm (and thus increases memory use) p parallelism factor t increasing T increases running time without increasing memory use g the number of times the hash has been "upgraded", used for strengthening stored password hashes without requiring knowledge of the original password NROM read-only memory that the resulting key will be made to depend on DKLen the length of key to derive (output) Format Of these, $7$ hashes only use the following: N - encoded with 1 byte (character) r - encoded with 5 bytes (characters) p - encoded with 5 bytes (characters) Since $7$ also means fixed-length encoding, every parameter has a prespecified number of bytes that encode it and every one of the parameters comes in order: $7$Nrrrrrppppp$...$. Let's enclose each byte in [] square brackets: $7$[N][r1][r2][r3][r4][r5][p1][p2][p3][p4][p5]$...$. Further, this means 11 is the exact number of bytes required (hence why it's not compact) for parameters in the sequence specified. On the other hand, $y$ hashes require three parameters: flags - encoded with at least 1 byte (character) N - encoded with at least 1 byte (character) r - encoded with at least 1 byte (character) Still, $y$ hashes can use all parameters by encoding them with variable-length. Effectively, this means each parameter is prefixed with its own size # encoded in the first byte and continues with # bytes: $y$[flags_len=#][flags1]...[flags#][N_len=#][N1]...[N#][r_len=#][r1]...$...$ To make things even more complex, the mandatory parameters are followed by an optional have parameter. Based on the value of have, yescrypt decides which, if any of p, t, g, and NROM are also part of the supplied data. For comprehensive guidelines about the parameters and which ones to use in what situations, it's probably best to consult the yescrypt PARAMETERS file on the OpenWall GitHub. Encoding Decoding the parameter fields is done via decode64_uint32(), which uses an array, indexed by atoi64() with the difference between the ASCII values of the current byte and the . period character (46), which is the base: atoi64_partial[77] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 64, 64, 64, 64, 64, 64, 64, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 64, 64, 64, 64, 64, 64, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 }; For each field, starting from the first field byte yescrypt performs the following actions: Use the first field byte to index the array as described above. Perform calculations with the array item to get a partial value for the field. Perform calculations with the array item to get the number of following bytes that encode the rest of the field value. For each next byte, the algorithm uses it to index the array again and adds the data to reach the final field value. There is some pseudo-code for other processes in the BitcoinWiki Yescrypt functions section. Demo Parameter Encoding Let's take an example from the PARAMETERS file above: flags = YESCRYPT_DEFAULTS N = 4096 r = 32 p = 1 t = 0 g = 0 NROM = 0 The above set of values is described as a standard Large and slow (memory usage 16 MiB, performance like bcrypt cost 2^8 - latency 10-30 ms and throughput 1000+ per second on a 16-core server) choice for Password hashing for user authentication, no ROM. $y$ is the signature. flags = YESCRYPT_DEFAULT = 182 = 0xB6 = j in yescrypt variable-length encoding. Here, flags should decode to YESCRYPT_DEFAULT, which is equivalent to YESCRYPT_RW_DEFAULTS, defined as (YESCRYPT_RW | YESCRYPT_ROUNDS_6 | YESCRYPT_GATHER_4 | YESCRYPT_SIMPLE_2 | YESCRYPT_SBOX_12K): YESCRYPT_RW = 0x002 YESCRYPT_ROUNDS_6 = 0x004 YESCRYPT_GATHER_4 = 0x010 YESCRYPT_SIMPLE_2 = 0x020 YESCRYPT_SBOX_12K = 0x080 Performing the logical OR operation, yescrypt arrives at the final number and encodes it. N = 4096 = 0x1000 = 9 in yescrypt variable-length encoding. In fact, N = 2decoded_N_field. r = 32 = 0x20 = T in yescrypt variable-length encoding. $ at this point tells yescript that no optional parameters were specified. Finally, the salt is added. It is theoretically of arbitrary length. However, the salt must be of a length that's a power of 4. $y$j9T$SALT$ Examples Here are a couple of valid but not secure examples, which may be visually helpful after the descriptions above: $7$9/..../..../$SALTS$ $y$./.$SALT$ $y$8/.$SALT$
What does j9T mean in yescrypt (from /etc/shadow)?
1,413,031,625,000
There are a number of existing guides online that already cover how to reencrypt a disk, such as maxschelpzig's response here and the documentation in the Arch wiki. However, the Arch wiki focuses more on systems that use mkinitcpio as opposed to dracut, and the existing StackExchange answer assumes an ext4 filesystem.
This assumes a default Fedora installation, with the following Btrfs-based partitions: Root partition (Btrfs subvolumes "root" [mounted at /] and "home" [mounted at /home]) Boot partition (mounted at /boot) EFI partition (UEFI systems only, mounted at /boot/efi) Requirements A full-disk backup cryptsetup (should be included, otherwise install with dnf install cryptsetup) At least 100 MiB of free space A rescue system that can unmount the root filesystem (ex. Fedora live USB) NOTE: The encryption screen will use the keyboard layout defined in /etc/vconsole.conf (set with localectl). The layout cannot be changed at boot time. Instructions Identify the root filesystem with lsblk -f. Store the UUID (format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) for later use. Identify your current kernel version with uname -r, and save this value for later. Reboot into the rescue system. Locate the root filesystem with blkid --uuid <UUID>, and run a check on the filesystem with btrfs check <device> Mount the filesystem with mount /dev/<device> /mnt Shrink the filesystem to make room for the LUKS header. At least 32 MiB is recommended, use btrfs filesystem resize -32M /mnt Unmount the filesystem: umount /mnt Encrypt the partition with cryptsetup reencrypt --encrypt --reduce-device-size 32M /dev/<device>, providing a passphrase when prompted. Identify the encrypted LUKS partition with lsblk -f (note that the UUID has changed). Save this LUKS partition UUID for later use. Open the partition, providing your passphrase when prompted: cryptsetup open /dev/<device> system Mount the mapped filesystem with mount /dev/mapper/system /mnt Resize the filesystem to use all the space: btrfs filesystem resize max /mnt, then unmount the filesystem with umount /mnt Mount the root subvolume (the Linux filesystem root) with mount -t btrfs -o "noatime,subvol=root,compress=zstd:1" /dev/mapper/system /mnt Identify the devices for the boot and EFI partitions with lsblk. Mount the boot filesystem (mount /dev/<boot device> /mnt/boot), followed by the EFI filesystem for UEFI systems (mount /dev/<EFI device> /mnt/boot/efi). Bind-mount the pseudo filesystems /dev, /dev/pts, /proc, /run, and /sys, in the format of mount --bind /sys /mnt/sys Open a shell within the filesystem: chroot /mnt /bin/bash Open /etc/default/grub with a text editor, and modify the kernel parameters to identify the LUKS partition, and temporarily disable SELinux enforcing. Add these parameters, then save the changes and close the file: GRUB_CMDLINE_LINUX="[other params] rd.luks.uuid=<LUKS partition UUID> enforcing=0" Configure a relabelling of SELinux with touch /.autorelabel Regenerate the GRUB config: grub2-mkconfig -o /boot/grub2/grub.cfg Regenerate initramfs to ensure cryptsetup is enabled: dracut --kver <kernel version> --force Exit the chroot Unmount all filesystems in reverse order. (For filesystems mounted with --bind, the option -l can be used.) Close the LUKS partition with cryptsetup close system Reboot and log into the regular system. You'll be asked for your passphrase to decrypt the system during boot. Open /etc/default/grub in a text editor, and reenable SELinux enforcing by removing enforcing=0 from GRUB_CMDLINE_LINUX. Save and exit. Relabel SELinux again with touch /.autorelabel. Repeat step 18 to regenerate the GRUB config. Reboot and log into the system. This answer heavily derives from maxschelpzig's answer and the Arch wiki. It also pulls from ceremcem's answer. On March 16th 2023 a typo was corrected where --reduce-device-size incorrectly contained a space.
How to encrypt an existing disk on Fedora without formatting?
1,413,031,625,000
I was wondering, if it was possible to use LUKS encryption with tape drives, QIC for instance. I'm using LUKS for USB drives and internal disks, even DVDs and CDROMs. But I was thinking of maybe using it to encrypt tape drives as well. Should I just use cryptsetup luksFormat directly to the tape drive and then enable the device with cryptsetup luksOpen?
You are unlikely to be happy with the huge latencies introduced by LUKS on linear media. A better idea is to pipe the output of tar through OpenSSL, encrypting it with a streaming cipher, before sending it to the tape device.
LUKS encryption for tape media?
1,413,031,625,000
I have an encrypted share folder on my synology NAS DS413 (which uses ecryptfs). I can manually mount the encrypted folder and read the decrypted files without issue, using synologies GUI. For some reason, I have never been able to mount the encrypted folder using my passphrase . But I can always do it by using the private key generated during ecryptfs setup. So I have since been doing some research on decrypting the encrypted files without a synology (for example if this thing catches fire or is stolen and I need to restore from backup). I've read several threads and howto's on decrypting synology/ecryptfs encrypted shares using linux and encryptfs-utils. But the howto always tells you to provide the passphrase and never mention the use of the key for decryption. So my question is how do I decrypt using the key (which works to mount and decrypt with synology's software)? The key I have is 80 bytes and is binary. The first 16 bytes are integers only and the remaining bytes appear to be random hex. Thanks for any tips!
Short answer: Use the passphrase $1$5YN01o9y to reveal your actual passphrase from the keyfile with ecryptfs-unwrap-passphrase (the backslashes escape the $ letters): printf "%s" "\$1\$5YN01o9y" | ecryptfs-unwrap-passphrase keyfile.key - Then use your passphrase with one of the instructions you probably already know, like AlexP's answer here or Robert Castle's article. Or do it all in a single line: mount -t ecryptfs -o key=passphrase,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_passthrough=no,ecryptfs_enable_filename_crypto=yes,passwd=$(printf "%s" "\$1\$5YN01o9y" | ecryptfs-unwrap-passphrase /path/to/keyfile.key -) /path/to/encrypted/folder /path/to/mountpoint I just tested the whole decryption process with a keyfile and can confirm its working: Created a new encrypted shared folder in DSM 6.2 and downloaded the keyfile. Shut down the NAS, removed a drive, connected it to a Ubuntu x64 18.04.2 machine and mounted the raid and volume group there. Installed ecryptfs-utils and successfully got access to the decrypted data using the mount command mentioned above with the downloaded keyfile. Credits: I found that $1$5YN01o9y-passphrase in a post in a German Synology forum. The user that probably actually found out the secret in 2014 is known there as Bastian (b666m).
how to decrypt ecryptfs file with private key instead of passphrase
1,413,031,625,000
In gpg's man page, there are examples of key IDs : 234567C4 0F34E556E 01347A56A 0xAB123456 234AABBCC34567C4 0F323456784E56EAB 01AB3FED1347A5612 0x234AABBCC34567C4 and fingerprints : 1234343434343434C434343434343434 123434343434343C3434343434343734349A3434 0E12343434343434343434EAB3484343434343434 0xE12343434343434343434EAB3484343434343434 My intuition would have been that a leading 0 is for octal and a leading 0x for hexadecimal, but it does not seem like it is. What are the different representations?
NOTE: Before I begin, all the representations here are hexidecimal only. There isn't any other representation. Key IDs The man page seems pretty clear on where these values are coming from. The key IDs are a portion of the SHA-1 fingerprint. The key Id of an X.509 certificate are the low 64 bits of its SHA-1 fingerprint. The use of key Ids is just a shortcut, for all automated processing the fingerprint should be used. All these values are hex, the notation allows for either a number to be prefixed with 0x, a 0, or to simply begin with a non-zero value. NOTE: Using key IDs is inherently a bad idea since they're essentially taking a portion of the fingerprint to identify a given key. The problem arises in that it's somewhat trivial to generate collisions among key IDs. See this article for more on this issue, titled: Short key IDs are bad news (with OpenPGP and GNU Privacy Guard). excerpt Summary: It is important that we (the Debian community that relies on OpenPGP through GNU Privacy Guard) stop using short key IDs. There is no vulnerability in OpenPGP and GPG. However, using short key IDs (like 0x70096AD1) is fundementally insecure; it is easy to generate collisions for short key IDs. We should always use 64-bit (or longer) key IDs, like: 0x37E1C17570096AD1 or 0xEC4B033C70096AD1. TL;DR: This now gives two results: gpg --recv-key 70096AD1 Fingerprints Whereas the fingerprints: This format is deduced from the length of the string and its content or the 0x prefix. Note, that only the 20 byte version fingerprint is available with gpgsm (i.e. the SHA-1 hash of the certificate). When using gpg an exclamation mark (!) may be appended to force using the specified primary or secondary key and not to try and calculate which primary or secondary key to use. The best way to specify a key Id is by using the fingerprint. This avoids any ambiguities in case that there are duplicated key IDs. I'd suggest taking a look at the wikipedia page titled: Public key fingerprint. It details how fingerprints are generated. Here's summary: excerpt A public key (and optionally some additional data) is encoded into a sequence of bytes. To ensure that the same fingerprint can be recreated later, the encoding must be deterministic, and any additional data must be exchanged and stored alongside the public key. The additional data is typically information which anyone using the public key should be aware of. Examples of additional data include: which protocol versions the key should be used with (in the case of PGP fingerprints); and the name of the key holder (in the case of X.509 trust anchor fingerprints, where the additional data consists of an X.509 self-signed certificate). The data produced in the previous step is hashed with a cryptographic hash function such as MD5 or SHA-1. If desired, the hash function output can be truncated to provide a shorter, more convenient fingerprint. This process produces a short fingerprint which can be used to authenticate a much larger public key. For example, whereas a typical RSA public key will be 1024 bits in length or longer, typical MD5 or SHA-1 fingerprints are only 128 or 160 bits in length. When displayed for human inspection, fingerprints are usually encoded into hexadecimal strings. These strings are then formatted into groups of characters for readability. For example, a 128-bit MD5 fingerprint for SSH would be displayed as follows: 43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8 References Fingerprint (computing)
GnuPG : representations of key IDs and fingerprints
1,413,031,625,000
UPDATE 1: userone@desktop:~$ sudo umount "/media/userone/New Volume" umount: /media/userone/New Volume: mountpoint not found userone@desktop:~$ sudo cryptsetup luksClose /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7 Device /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7 is not active. userone@desktop:~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 1 29.5G 0 disk └─sdb1 8:17 1 29.5G 0 part └─luks_USB 252:3 0 29.5G 0 crypt sr0 11:0 1 1024M 0 rom userone@desktop:~$ sudo cryptsetup luksOpen /dev/sdb1 luks_USB Device luks_USB already exists. userone@desktop:~$ sudo mkdir /media/userone/luks_USB mkdir: cannot create directory ‘/media/userone/luks_USB’: File exists userone@desktop:~$ sudo mount /dev/mapper/luks_USB /media/userone/luks_USB mount: wrong fs type, bad option, bad superblock on /dev/mapper/luks_USB, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. userone@desktop:~$ dmesg | tail [20639.663250] JBD2: no valid journal superblock found [20639.663257] EXT4-fs (dm-3): error loading journal [20828.133606] JBD2: no valid journal superblock found [20828.133613] EXT4-fs (dm-3): error loading journal [20832.682397] JBD2: no valid journal superblock found [20832.682405] EXT4-fs (dm-3): error loading journal [20851.042343] JBD2: no valid journal superblock found [20851.042349] EXT4-fs (dm-3): error loading journal [21053.115711] JBD2: no valid journal superblock found [21053.115718] EXT4-fs (dm-3): error loading journal userone@desktop:~$ ORIGINAL QUESTION: When I plug in my encrypted USB drive, I get this message in a GNOME dialog: Error mounting /dev/dm-3 at /media/userone/New Volume: Command line mount -t "ext4" \ -o "uhelper=udisks2,nodev,nosuid" \ "/dev/dm-3" "/media/userone/New Volume"' exited with non-zero exit status 32: mount: wrong fs type, bad option, bad superblock on /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7, missing codepage or helper program, or other error. In some cases, useful info is found in syslog - try dmesg | tail or so. Anyone know how this can be corrected? It was working fine yesterday.
It looks as though the journal has become corrupt, doing some searches over the past few days, this seems to not be uncommon on devices that use LUKS. You could try running an fsck on the device, acknowledging that any data on the device may not be accessible after - you may like to use dd to make a copy of the drive before this. A common resolution appears to be to create the EXT4 file system from scratch with journaling disabled using mke2fs -t ext4 -O ^has_journal /dev/device. Obviously you would lose the advantages of having a journaled file system by doing this, and lose any data on the device! Problem This problem is that the EXT4 file system’s journal has become corrupt. The problem is perhaps made a little obscure due to the fact that the device is encrypted and the file system resides “inside” the encryption. Resolution There is a thread of comments below, however I thought a summary here would be more beneficial to anyone who might come across this in the future. Unencrypt the device, this allows us to get at the device that the EXT4 file system resides on: sudo cryptsetup luksOpen /dev/sdb1 luks_USB Create an image of the device that has been created in the previous step. We need to do this because file system checking utils generally won’t work on mounted devices, and although the device with EXT4 on isn’t mounted, it’s “parent” is. sudo dd if=/dev/dm-3 of=/tmp/USBimage.dd (add bs and count arguments as you see fit). Now we have an image, we can run the file system checks: sudo e2fsck /tmp/USBimage.dd any problems found can be evaluated and fixed as required. You can check to see if your file system has been fixed by attempting to mount the image: sudo mount -o loop /tmp/USBimage.dd /mnt At this point the OP was able to gain access to their files. While I would suggest wiping the USB stick and starting over (back to a known state, etc), I think it would be possible to unmount the image from /mnt and then copy if back onto the device that become corrupt: sudo dd if=/tmp/USBimage.dd of=/dev/dm-3
Mount error when automounting a LUKS-encrypted USB flashdrive
1,413,031,625,000
Is there a way to check if my home folder is encrypted? I believe I checked this option during the installation, but now I'm not sure.
Since you didn't specify the distro, I will describe the method for Ubuntu (and maybe its derivatives) Try looking for folders $HOME/.Private and $HOME/.ecryptfs. Any one or both should be present. or try ls -A /home this should give an output mentioning either one or both the two folders. Source: EncryptedHome - Ubuntu Help Wiki
Is my home folder encrypted?
1,413,031,625,000
Is there an E-Mail client for linux which allows to search old gpg encrypted mails (i.e. find all mails which contain a particular keyword in the body, including the encrypted ones).
Mutt has pretty good PGP integration. The wiki shows what settings you need to add to your .muttrc; these settings may already be present in the system-wide configuration file (for example, on Debian, PGP/gpg works out of the box). Mutt supports mbox, mh and maildir mailboxes. If you search in a mailbox that happens to contain encrypted mail, you'll be prompted for your gpg passphrase (if you haven't already entered it in this session either in mutt or in an external keyring program), and mutt will find occurrences in encrypted mails. Mutt doesn't have a command to search multiple mailboxes. If your mails are stored in single files, you can make symbolic links inside a single directory to make a huge mh-format mailbox; it may be a little slow. Also, I haven't used it, but Notmuch is a recent tool to manage email that supports gpg and is good at indexing, so it should support searches of encrypted mails.
E-Mail client in linux which allows to search encrypted mail
1,413,031,625,000
On Mac OS X, right now I use the following to back up a small project folder to a USB Flash drive: alias a='alias' a dateseq='date "+%Y-%m-%d %H:%M:%S"' a backup_proj='cp -a ~/code/MyProj "/Volumes/KINGSTON/MyProj `dateseq`" so each time I type backup_proj, the folder is backed up from the hard drive to the USB drive, and each project is also internally version controlled using Git. Each folder is only about 500kb so it takes a long time to even fill up 1GB (the Flash Drive is 16GB). The folder is backed up as: $ ls -1 /Volumes/KINGSTON/ MyProj 2012-05-27 08:20:50/ MyProj 2012-05-27 10:27:56/ MyProj 2012-05-27 14:53:01/ But I get paranoid and also want to back up to Google Drive or Dropbox so it will get uploaded to their server automatically, just by encrypting the whole folder and copying the single resulting file to Google Drive or DropBox's folder, and the password can be apple234321pineapple and specified on the command line. I wonder what is a good way to encrypt the folder into a single file so that it takes a non-practical time to crack? (can you please give the command line that will do it).
man zip From the man page: -e --encrypt Encrypt the contents of the zip archive using a password which is entered on the terminal in response to a prompt (this will not be echoed; if standard error is not a tty, zip will exit with an error). The password prompt is repeated to save the user from typing errors. Another option is SSL encryption, example: openssl des3 -salt -pass pass:password -in file.txt -out encfile.txt Maybe you can TAR the folder before using openssl to encrypt it. man openssl
On Mac OS X, how to encrypt a small folder and copy that to Google Drive or DropBox?
1,413,031,625,000
The Terrapin Attack on SSH details a "prefix truncation attack targeting the SSH protocol. More precisely, Terrapin breaks the integrity of SSH's secure channel. By carefully adjusting the sequence numbers during the handshake, an attacker can remove an arbitrary amount of messages sent by the client or server at the beginning of the secure channel without the client or server noticing it." How would you change the SSH configuration to mitigate this attack?
This sounds like a big scarry attack, but it's an easy fix. To mitigate the attack, see my Thwarting the Terrapin Attack article for SSH configuration details. Specifically you need to block the ETM HMACs and ChaCha20 cipher as follows: For recent RHEL-based Linux systems (Alma, Rocky Oracle, etc), this will work: # cat /etc/crypto-policies/policies/modules/TERRAPIN.pmod cipher@ssh = -CHACHA20* ssh_etm = 0 # update-crypto-policies --set DEFAULT:TERRAPIN Setting system policy to DEFAULT:TERRAPIN Note: System-wide crypto policies are applied on application start-up. It is recommended to restart the system for the change of policies to fully take place. Alternatively, you can force AES-GCM which is not vulnerable if your system doesn't have (or doesn't use) update-crypto-policies (eg, as noted by @StephenKitt, Debian/Ubuntu may not use crypto-policies by default): # cat /etc/ssh/sshd_config [...] Ciphers [email protected] Then test with the testing tool provided by the original researchers.
How do you mitigate the Terrapin SSH attack?
1,413,031,625,000
I'm trying to determine if I should re-setup my RAID array due to poor IO performance. First off, the system: i7 920 4 4TB WD 5400 Green drives CentOS 6.3 host Secondly, the disk setup: /dev/sda2,b2,c2,d2 are individually LUKS encrypted /dev/mapper/a2,b2,c2,d2 are all part of a software RAID5 /dev/md1 /dev/md1 has LVM on top of that LVM is used to separate /, /storage, and swap I choose this structure to allow for multiple instances of kcryptd, thinking that by doing this, I would get multithread support on encryption since one instance is running per drive. However, I'm beginning to wonder if that was a good idea. For instance, if I run a heavy decompression routine on a RAR file of random data, my IO Wait goes up to around 25% and it slows the overall system down. I'm wondering if all the instruction sets are getting backed up somehow due to all the kcryptd processes. Therefore, I'm considering changing to: /dev/sda2,b2,c2,d2 are put into /dev/md1 /dev/md1 is encrypted and mapped to /dev/mapper/1 LVM on top of /dev/mapper/1 This would drop down to a single kcrpytd process, which could be a bottleneck in it's own right, too. Does anyone think this will help with my IO issue?
Your layering is suboptimal because putting the raid 5 on top of the encryption means that you increase the number of encrypt/decrypt operations by 25 % - since 4 * 4 TB are encrypted. When putting the encryption on top of the raid 5 only 3 * 4 TB are encrypted. The reasoning behind that is: you don't have to encrypt parity data (which takes up 4 TB in your example) of encrypted data because it does not increase your security. Your presumption about multiple kcrypt processes is just that. When basing decisions on it, it is a premature optimization that may have quite the opposite effect. Your i7 is quite beefy, probably even including some special instructions that help to speed up AES - and the Linux kernel includes several optimized variants of cryptographic primitives that are automatically selected during boot. You can verify if the optimized routines for your CPU are used via looking at /proc/cpuinfo (e.g. flag aes there), /proc/crypto, lsmod (unless the aes modules are compiled into the kernel) and the kernel log. You should benchmark the throughput of kryptd without involving any slow disks to see what the upper bound really is (i.e. on a RAM disk using iozone). To be able to diagnose potential performance issues later it is also useful to benchmark your RAID-setup of choice without any encryption to get an upper bound on that end. In addition to the crypto topic, RAID 5 involves more IO-Operations than RAID 1 or 10. Since storage is kind of cheap perhaps it is an option to buy more harddisks and use another RAID level.
Poor IO due to LUKS/Software RAID/LVM ordering?
1,413,031,625,000
I'm surprised that this question is not asked more frequently, but (in RHEL) does LUKS support TPM's the way that Windows BitLocker does? If so, how is this feature implemented, and does it provide the same type of protections that BitLocker for Windows provides? BitLocker is very popular among businesses, and now that RHEL6 is getting FIPS certification for the disk encryption modules, it would be great if it also supported the same feature set. However, I do understand that with the way LUKS works, not every volume can be encrypted, since the system would need to read the /etc/fstab and the /etc/crypttab files in order to mount the volumes. I believe this is OK as long as /home, /var, and other directories chosen by the administrator are encrypted. I find it odd that "TPM" is not a tag on serverfault.
I've implemented support for storing your LUKS key in TPM NVRAM, and RHEL6 happens to be the one platform where all features are fully tested, see this post: [1] https://security.stackexchange.com/a/24660/16522
RHEL6 LUKS with TPM support?
1,413,031,625,000
Scenario: I want to connect from Client A to Client B using SSH/SFTP. I can not open ports on either client. To solve this issue, I got a cheap VPS to use as a relay server. On Client B I connect to the VPS with remote port forwarding as followed: ssh -4 -N -f -R 18822:localhost:22 <user>@<vps-ip> On the VPS I've set up local port forwarding using -g (global) like this: ssh -g -f -N -L 0.0.0.0:18888:localhost:18822 <user>@localhost That way I can connect from Client A directly to Client B at <vps-ip>:18888. Works great. Now my question is, how safe is this? As far as I know, SSH/SFTP connections are fully encrypted, but is there any chance of making it less secure by using the VPS in the middle? Let's assume these two cases: Case A: The VPS itself is not altered with, but traffic and files are monitored completely. Case B: The VPS is completely compromised, filesystem content can be altered. If I now send a file from Client A to Client B over SFTP, would it be possible for the company hosting the VPS to "intercept" it and read the file's (unencrypted) content?
What you did You used three ssh commands: While inside a B console you did: ssh -4 -N -f -R 18822:localhost:22 <user>@<vps> Command sshd (the server) to open port 18822, a remote port vps:18822 connected to localhost (B) port 22. While at a vps console you did: ssh -g -f -N -L 0.0.0.0:18888:localhost:18822 <user>@localhost Command ssh (the client) to open port 18888 available as an external (0.0.0.0) port on (vps) that connects to internal port 18822. That opens an internet visible port vps:18888 that redirects traffic to 18822 which, in turn, redirects to B:22. While at a A console (and the only connection in which A participate): Connect from Client A directly to Client B at vps:18888. What matters is this last connection. The whole SSH security depends on the authentication of A to B. What it means The SSH protocol SSH provides a secure channel over an unsecured network By using end-to-end encryption End-to-end encryption (E2EE) is a system of communication where only the communicating users can read the messages. In principle, it prevents potential eavesdroppers – including telecom providers, Internet providers, and even the provider of the communication service – from being able to access the cryptographic keys needed to decrypt the conversation. End to end encryption is a concept. SSH is a protocol. SSH implements end to end encryption. So can https, or any other number of protocols with encryption. If the protocol is strong,and the implementation is correct, the only parties that know the encrypting keys are the two authenticated (end) parties. Not knowing the keys and not being able to break the security of the protocol, any other party is excluded from the contents of the communication. If, as you describe: from Client A directly to Client B you are authenticating directly to system B, then, only Client A and client B have the keys. No other. Q1 Case A: The VPS itself is not altered with, but traffic and files are monitored completely. Only the fact that a communication (day, time, end IPs, etc.) is taking place and that some amount of traffic (kbytes, MBytes) could be monitored but not the actual contents of what was communicated. Q2 Case B: The VPS is completely compromised, filesystem content can be altered. It doesn't matter, even if the communication is re-routed through some other sites/places, the only two parties that know the keys are A and B. That is: If the authentication at the start of the communication was between A and B. Optionally, check the validity of the IP to which A is connecting, then: use public key authentication (use only once a private-public key pair that only A and B know), done. Understand that you must ensure that the public key used is carried securely to the system B. You can not trust the same channel to carry the keys and then carry the encryption. There are Man-in-the-middle attacks that could break the protocol. Q3 If I now send a file from Client A to Client B over SFTP, would it be possible for the company hosting the VPS to "intercept" it and read the file's (unencrypted) content? No, if the public keys were safely placed on both ends, there is a vanishingly small probability of that happening. Walk with the disk with the public key to the other side to install it, never worry again. Comment From your comment: Q1 So, basically the VPS in my setup does nothing but forward the ports, and is not involved in the actual SSH connection or authentication happening from Client A to B, correct? Kind of. Yes the VPS should not be involved in the authentication. But it is "In-The-Middle", that is, it receives packets from one side and delivers them (if it is working correctly) to the other side. But there is an alternative, the VPS (or anything In-The-Middle) could choose to lie and perform a "Man-In-The-Middle-Attack". It could lie to Client-A pretending to be Client-B and lie to Client-B pretending to be Client-A. That would reveal everything inside the communication to the "Man-In-The-Middle". That is why I stress the word should above. I should also say that: ...there are no tools implementing MITM against an SSH connection authenticated using public-key method... Password-based authentication is not the public-key method. If you authenticate with a password, you could be subject to a Man-In-The-Middle-Attack. There are several other alternatives but are out of scope for this post. Basically, use ssh-keygen to generate a pair of keys (lets assume on side A), and (for correct security) carry the public part inside a disk to Side B and install it in the Authorized-keys file. Do not use the network to install the public key, that is: do not use the ssh-copy-id over the network unless you really do know exactly what you are doing and you are capable of verifying the side B identity. You need to be an expert to do this securely. Q2 About the public key though, isn't it, well, public? Yes, its public. Well, yes, the entity that generated the public-private pair could publish the public part to anyone (everyone) and have lost no secrets. If anybody encrypts with its public key only it could decrypt any message with the matching (and secret) private key. SSH encryption. By the way, the SSH encryption is symmetric not asymmetric (public). The authentication is asymmetric (either DH (Diffie-Hellman) (for passwords) or RSA, DSA, Ed25519 Key strength or others (for public keys)), then a symmetric key is generated from that authentication and used as communication encryption key. Used for authentication. But to SSH, the public key (generated with ssh-keygen) carry an additional secret: It authenticates the owner of the public key. If you receive a public key from the internet: How do you know to whom it belongs? Do you trust whatever that public key claims it is? You should not !! That is why you should carry the public key file to the remote server (in a secure way) and install it there. After that, you could trust that (already verified) public key as a method to authenticate you to log-in to that server. Q3 I've connected from the VPS, mostly for testing, to Client B before too, doesn't that exchange the public key already? It exchange one set of public keys (a set of DH generated public keys) used for encryption. Not the authentication public key generated with ssh-keygen. The key used on that communication is erased and forgotten once the communication is closed. Well, you also accepted (and used) a key to authenticate the IP of the remote server. To ensure that an IP is secure gets even more complex than simple(??) public-key authentication. My impression was that the public key can be shared, but the private key or passphrase must be kept safe. And your (general) impression is correct, but the devil is in the details ... Who generated a key pair could publish his public key without any decrease of his security. Who receives a public key must independently confirm that the public key belongs to whom he believes it belongs. Otherwise, the receiver of a public key could be communicating with an evil partner. Generate your key
How safe is SSH when used for tunneling?
1,413,031,625,000
On Debian 12.04 LTS I am trying to access the key net.ipv4.conf.all.mc_forwarding by doing : sudo sysctl -w net.ipv4.conf.all.mc_forwarding=1 But every time I am doing this, I get the message error: permission denied on key 'net.ipv4.conf.all.mc_forwarding' Why do I get this message? How can I change this key?
I believe this thread (EDIT: link to bit-coin miner site removed) describes your problem In a nutshell, the proc entry containing that value is read-only, and cannot be made writable easily: $ ls -ln /proc/sys/net/ipv4/conf/all/mc_forwarding -r--r--r-- 1 0 0 0 Jun 17 08:20 /proc/sys/net/ipv4/conf/all/mc_forwarding $ sudo chmod u+x /proc/sys/net/ipv4/conf/all/mc_forwarding chmod: changing permissions of `/proc/sys/net/ipv4/conf/all/mc_forwarding': Operation not permitted But you can run your own router daemon to (e.g xorp) to get multicast forwarding.
net.ipv4.conf.all.mc_forwarding: why is my access denied?
1,413,031,625,000
I made a mistake of encrypting the entire LVM physical volume (contains both home, root, and swap) when installing a CentOS 6.4 (2.6.32-358.6.1.el6.x86_64) box. I soon came to realize that moving files takes a horrendous amount of time due to kcryptd running at 90% of CPU and that encryption was not really necessary as it's just a home server containing no crucial data. However, I already configured it and installed loads of packages, tuned it as far as power management goes, and set up all the services. Is there any way to remove the encryption without having to re-install the whole thing and go through the configuration all over again? I'd love an option that would take less than 30 mins but I'm not sure one exists. Also, if anyone has any recommendations on how to make kcryptd more easy to use, let me know. Edit 1 ~]# fdisk -l /dev/sda Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000078c9 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 19458 155777024 83 Linux ~]# dmsetup ls vg_centos-lv_home (253:3) vg_centos-lv_swap (253:2) vg_centos-lv_root (253:1) luks-2ffcc00c-6d6e-401c-a32c-9c82995ad372 (253:0) ~]# pvdisplay --- Physical volume --- PV Name /dev/mapper/luks-2ffcc00c-6d6e-401c-a32c-9c82995ad372 VG Name vg_centos PV Size 148.56 GiB / not usable 4.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 38030 Free PE 0 Allocated PE 38030 PV UUID euUB66-TP3M-ffKp-WhF5-vKI5-obqK-0qKoyZ Edit 2 ~]# df -h / /home /boot Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 50G 2.3G 45G 5% / /dev/mapper/vg_centos-lv_home 94G 1.3G 88G 2% /home /dev/sda1 485M 53M 408M 12% /boot
That is possible. It requires another Linux to boot (CD/DVD is OK) some spare space outside the PV (100M would be good) a certain amount of fearlessness... Then you copy a block from the encrypted volume to the area outside the PV and (after success) to the unencrypted base device. After that you increase a counter in the safe area so that you can continue the transformation in case of a crash. Depending on the kind of encryption it may be necessary (or at least useful) to copy from the end of the block device to the beginning. If this is an option for you then I can offer some code. Edit 1 Deactivate the swap partition (comment it out in etc/fstab). Then boot another Linux (from CD/DVD) and open the LUKS volume (cryptsetup luksOpen /dev/sda2 lukspv) but don't mount the LVs. Maybe you need run pvscan afterwards to that the decrypted device is recogniced. Then vgchange -ay vg_centos may be necessary to activate the volumes. As soon as they are you can reduce the file systems in them: e2fsck -f /dev/mapper/vg_centos-lv_root resize2fs -p /dev/mapper/vg_centos-lv_root 3000M e2fsck -f /dev/mapper/vg_centos-lv_home resize2fs -p /dev/mapper/vg_centos-lv_home 2000M After that you can reduce the size of the LVs (and delete the swap LV): # with some panic reserve... shouldn't be necessary lvresize --size 3100M /dev/mapper/vg_centos-lv_root lvresize --size 2100M /dev/mapper/vg_centos-lv_home lvremove /dev/mapper/vg_centos-lv_swap # vgdisplay should show now that most of the VG is free space vgdisplay Now the PV can be reduced (exciting, I have never done this myself ;-) ): vgchange -an vg_centos pvresize --setphysicalvolumesize 5500M /dev/mapper/lukspv Edit: Maybe pvmove is needed before pvresize can be called. In case of an error see this question. Before you reduce the partition size you should make a backup of the partition table and store it on external storage. sfdisk -d /dev/sda >sfdisk_dump_sda.txt You can use this file for reducing the size of the LUKS partition. Adapt the size (in sectors) to about 6 GiB (panic reserve again...): 12582912. Then load the adapted file: sfdisk /dev/sda <sfdisk_dump_sda.mod.txt If everything looks good after rebooting you can create a new partition in the free space (at best not consuming all the space, you probably know why meanwhile...) and make it an LVM partition. Then make the partition a LVM PV (pvcreate), create a new volume group (vgcreate) and logical volumes for root, home and swap (lvcreate) and format them (mke2fs -t ext4, mkswap). Then you can copy the contents of the opened crypto volumes. Finally you have to reconfigure your boot loader so that it uses the new rootfs. The block copying I mentioned in the beginning is not necessary due to the large amount of free space.
What's the easiest way to decrypt a disk partition?
1,413,031,625,000
I've got a simple encrypted file with a bit of text inside. It's encrypted with des3 and I know the key. However, I can't for the life of me get it to decrypt in my kali VM. It works fine in a LInux Mint VM however. I'm at my wits end here.... What am I doing wrong? Here's the working decryption: user@user-virtual-machine ~/Desktop $ openssl des3 -d -in TheKeyIsInHere.des3 -pass pass:aramisthethird GJC13 says the key is nuorjbwyldurrurykpym user@user-virtual-machine ~/Desktop $ And here's the broken one: root@chkali:~/Desktop/new# openssl des3 -d -in TheKeyIsInHere.des3 -pass pass:aramisthethird bad decrypt 139786246681728:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:crypto/evp/evp_enc.c:529: �c]z��6z��oք��n&ΰ�Xqroot@chkali:~/Desktop/new# The file is the same in both cases (verified by md5sum).
The default hash used by openssl enc for password-based key derivation changed in 1.1.0 to SHA256 versus MD5 in lower versions. This produces a different key from the same password (and salt if used as it usually is), and trying to encrypt and decrypt with different keys produces garbage, an error, or both. To fix this for existing data specify -md md5 in 1.1.0 to decrypt data from lower versions, and -md sha256 in lower versions to decrypt data from 1.1.0. Going forward, consider specifying -md explicitly. For details see https://crypto.stackexchange.com/questions/3298/is-there-a-standard-for-openssl-interoperable-aes-encryption/35614#35614 (disclosure: mine)
Why can one box decrypt a file with openssl, but another one can't?
1,413,031,625,000
I want to create a script that would automatically encrypt and push to GitHub into public repo some sensible files I don't want to expose (but do want to keep together with the whole project). As a solution I decided to encrypt them with GPG. The issue is that I can't find any clues on how to encrypt a particular file with a passphrase passed as a CLI argument to a gpg -c command. Does anybody know how to do this?
Use one of the --passphrase-... options, in batch mode: --passphrase-fd reads the passphrase from the given file descriptor echo mysuperpassphrase | gpg --batch -c --passphrase-fd 0 file --passphrase-file reads the passphrase from the given file echo mysuperpassphrase > passphrase gpg --batch -c --passphrase-file passphrase file --passphrase uses the given string gpg --batch -c --passphrase mysuperpassphrase file These will all encrypt file (into file.gpg) using mysuperpassphrase. With GPG 2.1 or later, you also need to set the PIN entry mode to “loopback”: gpg --batch -c --pinentry-mode loopback --passphrase-file passphrase file etc. Decryption can be performed in a similar fashion, using -d instead of -c, and redirecting the output: gpg --batch -d --passphrase-file passphrase file.gpg > file etc.
Encrypt with GPG using a key passed as CLI argument
1,413,031,625,000
Setup: I'm using a raspberry pi with a USB HDD, running arch linux and syncthing for my own "cloud" sync. Problem: In case of a physical break-in where the HDD pi and HDD is stolen, I'd like to ensure that the files on the HDD remain confidential. Current, high level idea: Encrypt HDD, store key on webserver. On boot, download key, decrypt and mount. Don't store key on HDD/SD card. In case of theft, stop serving key from webserver. Question: How to go about implementing this? (Can crypttab solve this? Is writing my own systemd units the way to go? Any other ideas, or maybe even solution are welcome)
The easiest way to set this up would be to have a cleartext system partition (on the SD card, I presume) and an encrypted data partition. Use dmcrypt to encrypt the data partition, with a key stored in a key file that's downloaded from the server. First set up the server infrastructure, then download the key file and create the encrypted volume with cryptsetup luksFormat /dev/sdb1 /run/data.keyfile or add the key to the existing volume with cryptsetup luksAddKey /dev/mapper/encrypted /run/data.keyfile. Note that you can arrange for the volume to be unlocked with either a passphrase or a key file, which may be convenient for administration (you can type the passphrase even if the server is not available). The key file doesn't have to be in any particular format. Just generate some random bytes on the server; 16 bytes is plenty (anything more won't give you better security, but anything less won't give you better performance): </dev/urandom head -c 16 >pi.keyfile. Serve the key with HTTPS to avoid it being snooped. If you don't have a certificate that's validated by a CA, create your own and add it to /etc/ssl/certs, or pass it to the download command (wget --ca-certificate /etc/local/my.cert or curl --cacert /etc/local/my.cert). You need to download the key before activating the encrypting volume. You can do that in one step with one of wget -nv -O - https://myserver.example.com/pi.keyfile | cryptsetup luksOpen /dev/sdb1 --key-file /dev/stdin curl https://myserver.example.com/pi.keyfile | cryptsetup luksOpen /dev/sdb1 --key-file /dev/stdin or you can download the key to a temporary file, then activate the volume, and finally (not necessary, but may slightly improve security) remove the temporary file. The natural place for this temporary file is in /run, which is in RAM and writable only by root (don't download the key to persistent storage). You should make the file readable only by root (you can set umask 700 before downloading to arrange that), although it only matters if you don't control all the code that runs at boot time. If you download the key to a temporary file, you can put the keyfile in /etc/crypttab, and add a systemd unit to download the keyfile that runs before the one that activates encrypted volume (but after the network is available) and another unit to remove the keyfile afterwards. Putting wget … | cryptsetup … in /etc/rc.local looks easier to set up. You'll probably want to authenticate the client when it downloads the key. The authentication token will have to be stored in cleartext on the Pi. You can use an SSL client certificate: curl --cert /etc/keyfile.cert https://myserver.example.com/pi.keyfile wget --certificate /etc/keyfile.cert https://myserver.example.com/pi.keyfile or a password with HTTP basic authentication, stored in /root/.netrc: curl -n --user=pi https://myserver.example.com/pi.keyfile wget --user=pi /etc/keyfile.cert https://myserver.example.com/pi.keyfile Configuring basic authentication is perhaps easier to set up on the server side. Use a randomly-generated password with no special characters (e.g. </dev/urandom | head -c 16 | base64). Note that whatever you do, someone who steals the Pi will get the password and will be able to download the key if you don't block it first on the sender side. Also, someone who gets physical access to the Pi can quickly pull out the SD card, make a copy, and insert it back; if you don't monitor anything other than uptime, this will look like a power failure. There's no way to completely protect against that. You can put the key in a smartcard, which would prevent the attacker from duplicating it, but not from stealing the smartcard or using it on the spot to download the key file. Once again, you cannot protect against someone with physical access quickly downloading the key file, then stealing the disk and decrypting it at their leisure. If you want to protect against that, you need to look into tamper-resistant hardware, which is in a different price range.
How to not store hdd encryption key on machine, but still mount on boot?
1,413,031,625,000
When generating private/public keys with ssh-keygen what types of keys will it generate if I wont pass -t option followed with the encryption type like rsa?
From the man page: ssh-keygen can create RSA keys for use by SSH protocol version 1 and DSA, ECDSA or RSA keys for use by SSH protocol version 2. The type of key to be generated is specified with the -t option. If invoked without any arguments, ssh-keygen will generate an RSA key for use in SSH protocol 2 connections. So that's RSA by default. Note that ssh-keygen prints out what type of key it is generating in its first line of output.
What is the default encryption type of the ssh-keygen?
1,413,031,625,000
Trying to run this: gpg -c --passphrase-file secret somefiletoencrypt But it still asks for a password. How do we make gpg use the password in the secret to do symmetric encryption?
From the gpg manual (man gpg2 on my system), in the section talking about the --passphrase-file option: Note that since Version 2.0 this passphrase is only used if the option --batch has also been given. Since Version 2.1 the --pinentry-mode also needs to be set to loopback. Testing for myself with GnuPG 2.2.12, adding --batch to your command makes it work as expected.
gpg asks for password when supplying it in a file?
1,413,031,625,000
When unlocking a newly-formatted LUKS volume, I received a warning in the kernel log: kernel: device-mapper: table: 253:14: adding target device sdk1 caused an alignment inconsistency: physical_block_size=4096, logical_block_size=512, alignment_offset=0, start=33553920 According to another question, a false warning is possible, so I confirmed it's a true warning: 33553920 is not divisible by 4096. I further used luksDump to confirm: cryptsetup luksDump /dev/sdk1 | grep 'Payload offset' Payload offset: 65535 which is not a multiple of 8 (4096 ÷ 512 = 8) lsblk -t /dev/sdk confirms Linux is aware of the alignment requirements: NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME sdk 0 4096 33553920 4096 512 1 cfq 128 128 32M └─sdk1 0 4096 33553920 4096 512 1 cfq 128 128 32M dmsetup is documented to handle alignment itself, why did it create a misalignment? And are there arguments to luksFormat to avoid the problem?
It appears that dmsetup computes its alignment from the optimal I/O size, without bothering to check that that is actually a multiple of the physical block size. As mentioned in the false warning question, this optimal I/O size makes sense due to USB constraints. So the solution is simple: use --align-payload to override the detected value. A value of 8 should work (and produce the smallest possible header); the default when cryptsetup can't tell is documented as 2048. So I went with the default: cryptsetup luksFormat /dev/sdk1 --align-payload 2048 --verify-passphrase --hash sha512 -s 512 After that, the payload offset is now 4096 (from luksDump), and a kernel warning is still produced: kernel: device-mapper: table: 253:14: adding target device sdk1 caused an alignment inconsistency: physical_block_size=4096, logical_block_size=512, alignment_offset=0, start=2097152 ... but 2097152 is divisible by 4096, so that's the false warning mentioned in the other question. So the problem is resolved.
dmsetup luksFormat creating an alignment inconsistency
1,413,031,625,000
How can I encrypt/hide my - wpa-psk "password" - line in the /etc/network/interfaces file? Since it's uncovered and readable for everyone who can get in the file now. Or is it better that I use something else if I don't want to store my blank wifi password in a file? I'm running on debian without desktop environment.
The best you can do is hash the password. Set wpa-psk to the output of: wpa_passphrase <SSID> <KEY> This will obfuscate the password, but it will not prevent someone else from using the hash to connect with another device. As an additional measure you should also set /etc/network/interfaces file permission to rw------- (600), chmod og-rw.
How to encrypt/hide password in /etc/network/interfaces file on debian?
1,413,031,625,000
I have a process which I would like to have access to an encrypted file system. This is very easy to do with EncFS, but this requires a user mounting the encrypted file system, therefore giving any user who has access to the mounting user access to the data, e.g. root. Is it possible to have the process mount the file system so that only it has access to the data? If not, is there another way to prevent those who do not know the passphrase from accessing the data?
What Gilles said is correct, you can't prevent root from accessing the mount. It may not be able to access the mount directly (without the fuse allow_other option), but it can always switch to that user. However, what you can do is lazy unmount the mount after the process has changed it's current working directory into the mount point. Once the process is inside the mount point, you can do a lazy unmount. This will prevent any new processes from being able to access the mount point, but processes which were running inside it will continue to have access. Example encfs /enc/source /enc/target ( cd /enc/target && some_long_running_process) & fusermount -uz /enc/target some_long_running_process, and any children processes it spawns off will have full access to the mount point. But if anything not a child of that process tries to access the mount, it'll just get an empty directory. Note that there is a brief window where the mount point is available, in which something else can change directory into it, but the window is very small if scripted. Also note, there are still a few ways root could gain access to the mount point, but they're not simple, and are very hackish.
Use EncFS to encrypt files so that a particular user or process can access them, but root cannot
1,413,031,625,000
I have multiple keys (some private, some public) and I want to get information about them (their length, their type, anything else). Is that possible?
Based on the question tags, I’m assuming you’re asking about SSH keys. For public keys, you can ask ssh-keygen: ssh-keygen -lf /path/to/key.pub This will show you the key type (at the end of the output), its length (at the beginning), and its fingerprint. For private keys, you can ask openssl, but you’ll need to know the type: openssl rsa -text -noout -in /path/to/id_rsa You’ll need to provide the key’s passphrase, if any; you’ll then see the key size and all its contents.
Read key properties
1,413,031,625,000
For my home network I wanted to buy a NAS which supports disk encryption and NFS since it is important for me that the backup is encrypted but also that it preserves owner, groups and permissions (therefore NFS). This way I thought I could use something like rsnapshot or rBackup to backup my data and get multiple snapshots. Unfortunately I didn't find any NAS which supports NFS and encryption at the same time. So I was wondering if there is any possibility to get this using an NAS which without NFS (using for example CIFS instead of NFS). So I am looking for a backup solution which meets the following requirements: backup to a NAS in my local network (i.e. I don't want to use a local usb drive) it should preserve owner, groups and permissions and symbolic links it should be encrypted there should be multiple snapshots available like in rsnapshot or rBackup it should be easy to access the files of a snapshot it should be not too slow Any ideas how to do this in detail? Edit: I just try to sum up the answers so far and want to ask some additional question to clarify some points. It seems to be the most flexible option to use a container, FUSE or otherwise "faked" filesystem which doesn't depend on the target device. In this approach I can use any backup script I like and the encryption is done by the client CPU. The possibilities are: EncFS Truecrypt dmcrypt/luks S3QL I am not sure if it is possible to read and write on the NAS via S3QL from two clients simultanously. Is it correct that this is no problem for the other approaches? Concerning the permissions, in any case I have just to make sure to make it work with NFS. For example I could just make my backup script to preserve numerical uid/gid and setup no users on the NAS at all. EncFS seems to be the easiest solution so far. In Truecrypt and dmcrypt/luks I have to choose the containersize in advance which seems to be not so flexible as EncFS or Truecrypt. However are there any significant differences between those solutions concerning read/write performance and stability? Another interesting approach mentioned so far is to use duplicity as a backup script which does the encryption via gpg by itself.
You can use EncFS on top of NFS encfs /encrypted_place_at_nfs /mnt/place_to_access_it_unencrypted
Best way to make encrypted backups while preserving permissions to a windows file system
1,413,031,625,000
Emacs encrypts/decrypts .gpg files automatically. But recently I have lost the ability to decrypt files encrypted by the Linux gpg tool and vice versa. I use: passphrase symmetric encryption gnupg 1.4.11 emacs 24.0.92.1 Debian sid Decrypting using gpg (encrypted by emacs) gives: gpg: decryption failed: bad key Decrypting using emacs (encrypted by gpg) gives: epa-file--find-file-not-found-function: Opening input file: Decryption failed, Any idea how to avoid this?
The issue was in this (in Russian) solution which manipulates with input method. At present time it affects on passphrase during encryption/decryption.
Emacs auto encryption and gpg
1,413,031,625,000
I want to be able to route a portion of my traffic through another machine over SSH. For example, is it possible to browse the web through the ssh tunnel and also browse the web through your LAN connection without much effort? (i.e. I want a seamless transition from using tunnel to using LAN) Thus it is not a simple how do I tunnel ALL web traffic through ssh tunnel, but moreso how can I setup a tunnel that I can use at my discretion but not impeded my normal traffic flow. (Kind of on an as-needed basis) I would like the filtered traffic to be encrypted when leaving the LAN and it could be ftp, ssh, web, mail whatever traffic. Some questions I think I need to answer/address: Does this require multiple nics? Does this require setting up a proxy? Can I even do this the way I want it to function? Are there other options aside from a tunnel to achieve the result of having some traffic (user decides) encrypted through another machine (outside the LAN) and have other traffic use the normal flow through the LAN and out into the internet world? Edit: If some of the answers depend on specific traffic types I can be more specific and say that web traffic is a primary focus of this. However, other traffic such as IM/Email traffic would be desirable.
I don't know if that's what you're looking for, but you can use ssh -D4545 domain.com to open a socks proxy tunnel at port 4545 to the desired machine from your computer. You can then set up that proxy in your application (say Firefox) and use a plugin to quickly engage and disengage the proxy settings (something like TorButton). There is one drawback though: when your target host has more than one network device, you cannot control which one will your data take to leave the machine you're tunneling to. This can be circumvented by installing a normal proxy server on that machine, routing the traffic from, say, localhost:3128 to the desired network interface, and then doing a ssh -L4545:localhost:3128 and pointing all applications to 4545 that ought to use the proxy. This gives you greater control on the proxy side, as the integrated proxy of SSH is not really configurable.
Tunnel traffic through another machine over ssh
1,468,835,896,000
Assume I want to create a large encrypted drive stored in a file using cryptsetup, the first step is to create a random file, assume this should be of size 3T: dd if=/dev/urandom of=$FILE bs=1G count=3000 the above process can take really long time. I was wondering if the following short-cut makes any sense (from a security point of view, remember the goal is to create an encrypted drive stored in $FILE): dd if=/dev/urandom of=$FILE bs=1G count=1000 Make 3 copies of the above file, each file has size 1T and has the same random content Merge the 3 files to create one random file of the target size of 3T I guess that this procedure is not as rigorous as the data is a bit "less" random, but from a pragmatic point of view, is this a feasible solution (it would be almost 3 times faster)? Is this better than creating a 3T file full of zeros (using /dev/zero)?
/dev/urandom is way too slow for this amount of data. If pseudorandom is good enough: shred -v -n 1 /kill/me If encrypted random is good enough: cryptsetup open --type=plain /kill/me cryptkillme shred -v -n 1 /dev/mapper/cryptkillme cryptsetup close cryptkillme Encryption is slow too but still order of magnitude faster than /dev/urandom. shred should produce random looking data fast enough for any disk. Also note that for this size you really should be using a regular block device, not a file. If the filesystem that hosts the giant file ever goes corrupt, you're looking at an unsolvable puzzle with lots of pieces as a file of this size will usually be severely fragmented. If you stick to file anyway, you could consider not filling it with random data in the first place; you could use a sparse file instead and TRIM / punch_hole it to save storage space for unused areas. If overwriting old unencrypted data was your goal, you'd have to overwrite all free space in the filesystem as well, not just the container file itself as you won't know whether that's allocated in the same place as the unencrypted data you wanted to get rid of.
Creating a large file with random content: short-cut by copying?
1,468,835,896,000
When I installed Ubuntu 11.04 and I was offered the option of enabling "encrypted LVM" for my hard drive. After choosing that option, I am prompted for my password during boot to decrypt the LVM. Now, I am thinking about cancell/uninstall/remove "encrypted LVM' function as I don't want to input the "encrypted LVM" password every time when the system reboot. I know that you can setup a SSH to decrypt the LVM but that requires the installation of other programs. Is there a better/clean way to solve this problem like just uninstall the "encrypted LVM"? How to do it and this question is NOT specific to Ubuntu. Thanks.
There is no simple "remove encryption" command that will preserve your data. The Arch Wiki explains how to remove encryption and basically it describes the process of data backup, remove encryption, format fs, restore data. If you entered a long key, and you're tired of typing it every time you login, you could add a new, shorter key. Before you do any of the following you need to enter your key and backup the unencrypted data. cryptsetup luksAddKey /dev/mapper/encrypted Enter any passphrase: current_key_needs_to_be_entered Enter new passphrase for key slot: new_short_key Verify passphrase: new_short_key Your new passphrase can be short, just a few chars, 123 if you wish. This can be done quickly, but leaves the data encrypted with a short useless key. I would recommend following the wiki and eliminating the encryption.
Uninstall the Encrypted LVM function to remove the prompted password entry during Ubuntu Boot
1,468,835,896,000
I've upgraded my linux installation to kernel 2.6.38-2 (Debian testing). With the new kernel, loop-aes does not compile, so I cannot mount my encrypted volumes. I heared that it is possible to use some compatibility mode of cryptsetup to mount encrypted volumes of loop-aes, so my question is: How can I do that? I have been searching for hours with Google and couldn't find anything that worked. With loop-aes, I was mounting partitions with the following entry in /etc/fstab: /dev/sdb2 /mount/data ext4 user,noauto,loop,encryption=aes256 0 0 How would the cryptsetup command line look like? I would prefer an fstab entry, if possible, but a command line would do as well.
cryptsetup loopaesOpen <device> <name> [--key-size 128] --key-file <key-file>, according to http://code.google.com/p/cryptsetup/wiki/Cryptsetup130. If your cryptsetup isn't 1.3.0, you're gonna have to download that version and compile it. cryptsetup opens the volume and creates a new block device in /dev/mapper/<name> You then have to use the mount command after cryptsetup to actually use it. I know crypttab is involved in setting up boot-type encrypted volumes but I wrote my own scripts to manually mount them on demand so I have no experience with that, unfortunately.
Migration from loop-aes to cryptsetup
1,468,835,896,000
I have a gpg setup started with older gpg versions and I did not use a passphrase back then. I would type enter directly when prompted for it. I'm not sure if that means the key isn't encrypted or if it is encrypted with an empty passphrase. Regardless, when I try to decrypt something that was sent to me recently, gpg needs access to my private key and prompts me for a passphrase but now I cannot use an empty passphrase anymore. gpg fails with: $ gpg -d foo.asc (X dialog that prompts me for passphrase, I just press enter) gpg: public key decryption failed: No passphrase given gpg: decryption failed: No secret key I would like to be able to use my keys again. I don't mind setting a passphrase from now on but I don't know how: $ gpg --passwd [email protected] (X dialog that prompts me for current passphrase, I just press enter) gpg: key xxxxxxxxxxxxxxxx/aaaaaaaaaaaaaaaa: error changing passphrase: No passphrase given gpg: key xxxxxxxxxxxxxxxx/bbbbbbbbbbbbbbbb: error changing passphrase: No passphrase given gpg: error changing the passphrase for '[email protected]': No passphrase given I am running gpg (GnuPG) 2.2.5 and libgcrypt 1.8.2 on openSUSE 15.0.
I solved this by using an older system which had the key. I set a new passphrase on the old system where empty-passphrase input works. Export old system private key and copy it over new system Clean gpg state of new system (move .gnupg to .gnupg.bak) Import the non-empty passphrase private key Here are the commands I ran: # put a non-empty passphrase on current key me@old$ gpg --passwd [email protected] (leave empty on first prompt) (put a new non-empty passphrase on 2nd) (confirm new passphrase) # now we export it me@old$ gpg --list-secret-keys /home/xxxxx/.gnupg/secring.gpg ------------------------------- sec 4096R/AAAAAAAA 2015-01-01 uid Foo Bar <[email protected]> uid Bar Foo <[email protected]> ssb 4096R/BBBBBBBB 2015-01-01 # I've used the first key id (should be 8 hex digits) me@old$ gpg --export-secret-keys AAAAAAAA > priv.key # copy key over new system # backup .gnupg dir just in case me@new$ mv .gnupg .gnupg.back # import new priv key me@new$ gpg --import priv.key (type new passphrase set previously) # done! For completeness sake here are the software versions of both systems, maybe that can help someone: New system (cannot input empty passphrase) software version: gpg (GnuPG) 2.2.5 libgcrypt 1.8.2 pinentry-curses (pinentry) 1.1.0 Old system (can input empty passphrase) software version: gpg (GnuPG) 2.0.24 libgcrypt 1.6.1 pinentry-curses (pinentry) 0.8.3
gpg cannot unlock passphrase-less key: "gpg: public key decryption failed: No passphrase given"
1,468,835,896,000
I'm curious if there is a filesystem that's unencrypted, making it readable by anyone, but employs a digital signature scheme so as to require that writes be digitally signed. I suspect the answer is "No because it'd be complicated and probably slower than simply encrypting the drive" but seemed interesting.
The two obvious candidates would be ZFS and Btrfs, but as far as I know, they don't do this. Btrfs currently has no crypto at all (for encryption, you're supposed to use LUKS, which provides encryption and optionally block-level integrity but not global integrity). ZFS has an integrity mode where it uses a tree of cryptographic hashes to ensure that the filesystem remains consistent. If the root hash was signed, that would guarantee the authenticity of the filesystem: an adversary could not inject fake content. That would almost guarantee the integrity of the filesystem: all the adversary could do without the key would be to roll back the filesystem to an earlier version. An alternate way to ensure the integrity of the filesystem would be to store an offline copy of the root hash; I can't find a reference of existing tools to do this. Verifyfs is a FUSE filesystem which verifies the signature of files individually. As far as I can tell from a quick perusal (I hadn't heard of it before today), it does not sign directories, attempt to prevent rollbacks or verify the consistency of the filesystem, so an adversary can downgrade individual files to earlier versions and can erase files. Why is encryption so common and integrity verification so uncommon? I think there are several reasons: threats to integrity are somewhat less common than threats to confidentiality, they're are harder to combat, and integrity verification has a higher performance cost. Encryption protects against a disk getting stolen. It's a threat pretty much everywhere, and once the disk is stolen, there is no other remedy. Integrity verification protects against an adversary who has access to the system while the storage is unmounted (if it's mounted, the integrity verification key is in memory) — an evil maid attack. This is rarely a threat against servers, for which tampering is often detectable, but it is a threat against laptops. Even if you do manage to protect your disk against an evil maid attack by cryptographic means, your computer is still vulnerable to attacks that target firmware. PC usually have several flash memories which can be rewritten with no cryptographic protection (including the firmware of the disk itself). Integrity protection is costly because it's a global property. Encryption can be performed sector by sector, so the cost is small unless your CPU is very slow and your disk is very fast. If you authenticate sector by sector, an adversary can still partially compromise the system by reverting some sectors to an earlier value, although this is a more sophisticated attack as it may require access to the system at different times. So complete authenticity verification requires comparing a sector's authentication value with a reference value, whose authenticity and freshness itself needs checking, etc.
Is there an unencrypted but signed filesystems?
1,468,835,896,000
I have a single text file I want to encrypt. I can easily do so with any common software. But then, I want to be able to click on it, provide a password, and be able to read, edit, and close it. All from the GUI, which should be KDE-compatible, and possibly the editor should be Kate. Ideally, this should be available in a single KRunner call. Alternative CLI approach are OK but should be contained in a single command/function/alias. A possibility could be to create an encrypted folder. Then mount the folder only at access-time and unmount immediately after the closure of the text editor, all in a single CLI command. It looks a bit hackish to me tho, and I'd prefer to do the call from KRunner only. To summarize, following the ArchWiki a bit: I want to protect a single file in case my PC gets stolen. Of course professional data miners will get to it eventually, I accept that. The file should be accessible (read/write access) with a passphrase on-the-fly (on-demand) GUI methods are preferred but CLI methods are OK too, as long as they can be called with a .desktop file (to be accessed via KRunner) I don't have a preferred encryption method, as long as it's decently fast, secure and open-source. Structure and filenames of the encrypted folder (if this is the only way) can be transparent, as long as the content is inaccessible. Any encryption method is accepted, as long as it does not take minutes to verify a key, for example
For just one file at a time, or the very occasional file, I think a whole encrypted drive or home with EncFS/eCryptFS/dm-crypt/LUKS would be overkill (but would work excellent in case of theft). A solution using a bash function to decrypt, edit, re-encrypt sounds more like what you're looking for. Using gpg since it's installed by default on almost every linux I've seen, and has been around for decades & should be for decades more so looks suitable for long term archives. Something like this could be put into a .bashrc file & used in a terminal, or incorporated into a file manager's "right-click" menu should work too (I'm not familiar enough with KDE to do that, but if you are it shouldn't be terribly difficult). These quick little functions will take the first argument $1 as a filename to decrypt to /tmp/gpg-edit.out (can use a tmpfs/ramdisk for better security), edit with gedit (or your favourite editor), and re-encrypt the file when you're done editing. They use a "passphrase-file" where only the first line is read & used as a passphrase, so it should be kept somewhere secure (tmpfs/ramdisk perhaps) but you could omit that & gpg would ask you for the passphrase each time. edit-gpg() { gpg -v --no-use-agent --passphrase-file=/path/to/keyfile --output "/tmp/gpg-edit.out" "$1" && gedit "/tmp/gpg-edit.out" && gpg -v --no-use-agent --cipher-algo AES256 --passphrase-file=/path/to/keyfile --output "$1" -c "/tmp/gpg-edit.out" && rm "/tmp/gpg-edit.out" } Future To-Do's would include a check if the "/tmp/gpg-edit.out" file already exists (now gpg will ask to overwrite if it does). Or use a random output file so you could edit multiple files at once. For now, it's one at a time. Omitting --no-use-agent should have it use gpg's GUI passphrase entry box, but the last time I left out the option it would always use the GUI box and ignore the --passphrase-file option. Another short function can initially encrypt a file with the same passphrase-file: crypt-gpg() { gpg -v --no-use-agent --cipher-algo AES256 --passphrase-file=/path/to/keyfile -c "$1" && rm "$1" }
Encrypt a single file and read/edit on-the-fly
1,468,835,896,000
Here's the scenario, we're using GnuPG to encrypt data between 2 web servers. 1 is on RHEL. GnuPG will be accessed through cgi scripts to encrypt and decrypt. So I need a keyring that the apache user has access to. This has proven to be difficult for me on Red Hat, I was able to get this set up pretty easily on Ubuntu. Here's what I've tried to, maybe someone has a better/easier way to accomplish this. I became the apache user su -s /bin/bash apache when running gpg --gen-key it couldn't create the .gnupg directory at /var/www, so I created that and set the owner to apache.apache. now when generating keys, I get can't connect to `/var/www/.gnupg/S.gpg-agent': No such file or directory gpg-agent[26949]: command get_passphrase failed: Operation cancelled gpg: cancelled by user gpg: Key generation canceled. so I created that file, after reading the man page a bit (and some googling) mknod -m 700 S.gpg-agent p now I get can't connect to `/var/www/.gnupg/S.gpg-agent': Connection refused gpg-agent[26949]: command get_passphrase failed: Operation cancelled gpg: cancelled by user gpg: Key generation canceled. I haven't been able to get anywhere after this as I'm getting into areas I don't know much about. I'm assuming it has to do with that apache isn't really a user in the since of having a bash profile, etc. So where do I go from here?
Have you tried creating a new user and invoking the command with sudo instead? If fear this might be some permission issue and the easier way would be removing the agent node from /var/www to somewhere we know is accessible to the gpg user, maybe the /tmp directory. You can manually specify the agent node location changing the env variable GPG_AGENT_INFO.
Creating a GnuPG keyring for apache
1,468,835,896,000
I want to encrypt the content of a directory in a container with an ext4 filesystem using cryptsetup. The size of the container should be as small as possible and as big as necessary, because I only want to write once and then backup. First try: setting the size of the container to the size of the content. dirsize=$(du -s -B512 "$dir" | cut -f 1) dd if=/dev/zero of=$container count=$dirsize losetup /dev/loop0 $container fdisk /dev/loop0 # 1 Partition with max possible size cryptsetup luksFormat --key-file $keyFile /dev/loop0 cryptsetup luksOpen --key-file $keyFile /dev/loop0 container mkfs.ext4 -j /dev/mapper/container mkdir /mnt/container mount /dev/mapper/container /mnt/container rsync -r "$dir" /mnt/container Rsync returns that there is not enough space for the data. Seems reasonable as there has to be some overhead for the encryption and the file system. I tried it with a relative offset: dirsize=$(($dirsize + ($dirsize + 8)/9)) This fixes the problem for dirs with > 100 MB, but not for dirs with < 50 MB. How can I determine the respective amount of bytes the container has to be bigger than the directory?
LUKS by default uses 2 MiB for its header, mainly due to data alignment reasons. You can check this with cryptsetup luksDump (Payload offset: in sectors). If you don't care about alignment, you can use the --align-payload=1 option. As for ext4, it's complicated. Its overhead depends on the filesystem size, inode size, journal size and such. If you don't need a journal, you might prefer ext2. It may be that other filesystems have less overhead than ext*, might be worth experimenting. Also some of the mkfs flags (like -T largefile or similar) might help, depending on what kind of files you're putting on this thing. E.g. you don't need to create the filesystem with a million inodes if you're only going to put a dozen files in it. If you want the container to be minimal size, you could start out with a larger container, and then use resize2fs -M to shrink it to the minimum size. You can then truncate the container using that size plus the Payload offset: of LUKS. That should be pretty close to small, if you need it even smaller, consider using tar.xz instead of a filesystem. While tar isn't that great for hundreds of GB of data (need to extract everything to access a single file), it should be okay for the sizes you mentioned and should be smaller than most filesystems...
How much storage overhead comes along with cryptsetup and ext4?
1,468,835,896,000
I have a problem booting my Debian Linux server. After a system update, GRUB loads the initrd and the system should ask for the password, but it doesn't. Instead, I get dropped to BusyBox. After trying to mount the encrypted volume manually with cryptsetup luksOpen, I get this error: device-mapper: table: 254:0: crypt: Error allocating crypto tfm device-mapper: reload ioctl failed: Invalid argument Failed to setup dm-crypt key mapping for device /dev/sda3 Check that the kernel supports aes-cbc-essiv:sha256 cipher (check syslog for more info). Images
Your kernel lacks support for aes-cbc-essiv:sha256. “Error allocating crypto tfm” refers to the kernel's cryptographic subsystem: some necessary cryptographic data structure couldn't be initialized. Your support for cryptographic algorithms comes in modules, and you have a module for the AES algorithm and a module for the SHA-256 algorithm, but no module for the CBC mode. You will not be able to mount your encrypted device without it. If you compiled your own kernel, make sure to enable all necessary crypto algorithms. If your kernel comes from your distribution, this may be a bug that you need to report. In either case, there must be a module /lib/modules/2.6.32-5-amd64/kernel/crypto/cbc.ko. If the module exists, then your problem is instead with the initramfs generation script. In addition to the cbc module, you need other kernel components to tie the crypto together. Check that CRYPTO_MANAGER, CRYPTO_RNG2 and CRYPTO_BLKCIPHER2 are set in your kernel configuration. Debian's initramfs building script should take care of these even if they're compiled as modules. As the crypto subsystem is rather complex, there may be other vital components that are missing from the initramfs script. If you need further help, read through the discussion of bug #541835, and post your exact kernel version, as well as your kernel configuration if you compiled it yourself. You will need to boot from a rescue system with the requisite crypto support to repair this. Mount your root filesystem, chroot into it, mount /boot, and run dpkg-reconfigure linux-image-… to regenerate the initramfs.
Booting encrypted root partion fails after system update