Example 1: sudo sed -i "s/#user = "root"/user = "$(id -un)"/g" /etc/libvirt/qemu.conf
Example 2: sudo sed -i "s/#group = "root"/group = "$(id -gn)"/g" /etc/libvirt/qemu.conf

I search with google but no answers

  • 1
    What output did this give, it shouldn't work without escaping the middle " " (ie the quotes). Note that sed -i "s/A/B/g" /path/to/file takes all A in the given file and replaces it with B, to revert you can often switch the command to say s/B/A/g. Or you can type id -un && id -gn in your shell and look in the file with an editor for those lines starting "user = " and "group = " and ending in the numbers it gives you.
    – pbhj
    May 11 '21 at 20:11
  • Shellcheck gives useful hints: pastebin.com/gJ021KLH
    – pbhj
    May 11 '21 at 20:24

Sorry, but I can't leave this as a comment because I have too few points.

This is not Ubuntu-specific and can be used on other distributions as well

For example one:

sudo sed -i "s/user = "$(id -un)"/user = "root"/g" /etc/libvirt/qemu.conf

For example two:

sudo sed -i "s/group = "$(id -gn)"/group = "root"/g" /etc/libvirt/qemu.conf
  • Ok. I try when i get home.. thanks
    – odondonaga
    May 11 '21 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.