Docker Community Forums

Share and learn in the Docker community.

How to escape dollar signs in sed command?

(Quantumburnz) #1

I’m working with a Kali Linux container, and I want to be able to RDP into it using xrdp. In order to do this, I need to set the root password. However, by default, there’s no password so the shadow file just has * for the password. I only have a few modifications I want to make to the container so I’m just scripting a few changes using the docker exec command and sed to replace the asterisk with the password I want. Although, I’m running into problems because of the dollar signs ($) and the result is the asterisk is simply replaced with a period.

The following works fine if I execute this directly from the Linux command line interactively attached to the container:
sed -i ‘s/root:*/root:$6$tFLJi80y$Fxu…/’ /etc/shadow

However, I’ve tried multiple ways to get something like the following to work with no success:
docker exec $id sh -c “sed -i ‘s/root:*/root:$6$tFLJi80y$FxuEB…/’ /etc/shadow”

How in the world do I properly escape the dollar signs? Or, maybe there’s a smarter way to go about this.

OS Version/build: Win 10
App version: 18.03.1-ce-win65 (17513)