# Encrypt files on remote host

**URL:** <https://forum.ansible.com/t/encrypt-files-on-remote-host/36035>\
**Category:** Ansible Project\
**Created:** [November 25, 2021, 5:22pm UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035 "2021-11-25T17:22:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Steinhart](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Roman\_Steinhart](https://forum.ansible.com/u/Roman_Steinhart)\
**Post date:** [November 25, 2021, 5:22pm UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035/1 "2021-11-25T17:22:51Z")

</div>

Hi all,

I want to encrypt a file on a remote host. I was looking through the existing modules and couldn’t find any that is able to do that?

My use case is that I want to create a backup (tar file) on a remote host, encrypt the backup archive and upload it to some storage.

I’m aware of Ansible vault, but it’s intended purpose is for encrypting secrets etc. to use it in the playbook and not encrypting a remote file.  
Maybe someone has a suggestion.  
Thanks!  
~ Roman

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 25, 2021, 5:50pm UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035/2 "2021-11-25T17:50:37Z")

</div>

> Hi all,
> 
> I want to encrypt a file on a remote host. I was looking through the existing modules and couldn't find any that is able to do that?
> 
> My use case is that I want to create a backup (tar file) on a remote host, encrypt the backup archive and upload it to some storage.
> 
> I'm aware of Ansible vault, but it's intended purpose is for encrypting secrets etc. to use it in the playbook and not encrypting a remote file.  
> Maybe someone has a suggestion.  
> Thanks!  
> ~ Roman

Hello Roman,

how would you do the encryption without Ansible?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Roman\_Steinhart](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Roman\_Steinhart](https://forum.ansible.com/u/Roman_Steinhart)\
**Post date:** [November 26, 2021, 10:39am UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035/3 "2021-11-26T10:39:59Z")

</div>

Hi Stefan,

probably with openssl or gpg.  
See  
[https://gist.github.com/dreikanter/c7e85598664901afae03fedff308736b](https://gist.github.com/dreikanter/c7e85598664901afae03fedff308736b)  
[https://www.gnupg.org/gph/en/manual/x110.html](https://www.gnupg.org/gph/en/manual/x110.html)

I mean, I could do this with a basic shell module, but I’m wondering that there’s no module fur such actions.

Thanks,  
Roman

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [November 29, 2021, 8:17am UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035/4 "2021-11-29T08:17:50Z")

</div>

> Hi Stefan,
> 
> probably with openssl or gpg.  
> See  
> [https://gist.github.com/dreikanter/c7e85598664901afae03fedff308736b](https://gist.github.com/dreikanter/c7e85598664901afae03fedff308736b)  
> [https://www.gnupg.org/gph/en/manual/x110.html](https://www.gnupg.org/gph/en/manual/x110.html)
> 
> I mean, I could do this with a basic shell module, but I'm wondering that there's no module fur such actions.

Hello Roman,

yeah, I guess you need to use the command module (not the shell module) or a dedicated backup software that does the encryption.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [December 1, 2021, 12:31pm UTC](https://forum.ansible.com/t/encrypt-files-on-remote-host/36035/5 "2021-12-01T12:31:53Z")

</div>

Is it OK for an unencrypted copy of the backup to live on the to live on the remote storage, where it could be encrypted and uploaded? Ansible can have access to zip or GPG keys configured, especially publishing pubic GPG keys for use on the server that hosts the unencrypted file. The GPG public key need not be a secret: it could be published to the remote host to encrypt the file locally before upload.
