How do I change the user Transmission runs under?

I installed Transmission through a PPA and the daemon starts on boot. I want to change the user that runs the daemon because I want the downloaded files to be under the same user as my XBMC installation, and I can't seem to find where to edit that.

The daemon uses upstart so there is nothing about which users runs it in /etc/init.d/transmission-daemon and there isn't anything in /etc/default/transmission-daemon about the user either

I'm using these ppas for transmission:

/etc/apt/sources.list.d/transmissionbt-ppa-quantal.list:deb //ppa.launchpad.net/transmissionbt/ppa/ubuntu quantal main

/etc/apt/sources.list.d/transmissionbt-ppa-quantal.list:deb-src //ppa.launchpad.net/transmissionbt/ppa/ubuntu quantal main

/etc/apt/sources.list.d/transmissionbt-ppa-quantal.list.save:deb //ppa.launchpad.net/transmissionbt/ppa/ubuntu quantal main

/etc/apt/sources.list.d/transmissionbt-ppa-quantal.list.save:deb-src //ppa.launchpad.net/transmissionbt/ppa/ubuntu quantal main

Solution 1:

Since all of the other answers are for Ubuntu pre-systemd, here's an updated guide for Ubuntu 16.04 (from sensecodons.com). Essentially, create a supplementary unit for "transmission-daemon.service" to change the User=... setting and then update that user's "~/.config/transmission-daemon/settings.json" file.

Stop transmission (if it's already running).

sudo systemctl stop transmission-daemon

Create the supplement file directory for transmission:

sudo mkdir -p /etc/systemd/system/transmission-daemon.service.d

Create a new supplement file called "run-as-user.conf".

sudo vi /etc/systemd/system/transmission-daemon.service.d/run-as-user.conf

and put the following text in it.

[Service]
User=codon

Obviously, use your desired username and not "codon".

Tell systemd to reload its units.

sudo systemctl daemon-reload

Next, you'll want to start and then stop transmission to make it create the ~/.config/transmission-daemon/ directory for your new user.

Start transmission and then stop transmission.

sudo systemctl start transmission-daemon; sudo systemctl stop transmission-daemon

You should now have the following directory in your user's home directory: .config/transmission-daemon/

From here, you should be able to update ~/.config/transmission-daemon/settings.json normally.

When you're done, start transmission.

sudo systemctl start transmission-daemon

Solution 2:

Assumptions:

  • You used this PPA: ppa:transmissionbt/ppa
  • You want to run Transmission with user: some_user and group: some_group

For System V (SysV) init system (eg: Ubuntu 10.04 LTS):

  1. Stop the Transmission Daemon:

    sudo service transmission-daemon stop
    
  2. Edit the init.d scripts

    sudo nano /etc/init.d/transmission-daemon
    

    ...and change USER=debian-transmission to USER=some_user

For Upstart init system (eg: Ubuntu 14.04 LTS):

  1. Stop the Transmission Daemon:

    sudo service transmission-daemon stop
    
  2. Edit the init scripts:

    sudo nano /etc/init/transmission-daemon.conf
    

    ...and edit as follows:

    • change setuid debian-transmission to setuid some_user

    • and change setgid debian-transmission to setgid some_group

For systemd init system (eg: Ubuntu 16.04 LTS):

  1. Stop the Transmission Daemon:

    sudo systemctl stop transmission-daemon.service
    
  2. Create systemd override.conf file:

    sudo systemctl edit transmission-daemon.service
    

    ...and edit as follows:

    [Service]
    User=
    User=some_user
    Group=
    Group=some_group
    

    Notes:

    • This creates the following file: /etc/systemd/system/transmission-daemon.service.d/override.conf

    • The empty variable assignments (eg: User=) are used to clear/reset the value in the existing variable. This seems to be how things are done when using drop-in replacement of the systemd unit file. See: "Example 2. Overriding vendor settings" in systemd.unit manual:

      "...for drop-in files, if one wants to remove entries from a setting that is parsed as a list (and is not a dependency), ... one needs to first clear the list before re-adding all entries except the one that is to be removed..."

  3. Systemd reload and start transmission daemon:

    sudo systemctl daemon-reload
    sudo systemctl start transmission-daemon.service
    

    Note: Unlike with Upstart and SysV init systems transmission-daemon saves all configuration and settings in /home/some_user/.config/transmission-daemon/ instead of /etc/transmission-daemon/settings.json and /var/lib/transmission-daemon

Notes & References

  • /etc/default/transmission-daemon is used only by the Upstart scripts (/etc/init.d/transmission-daemon) and SysV scripts (/etc/init/transmission-daemon.conf) and so if you are using Systemd init system then you can ignore all these files.

  • Running transmission as a user in Ubuntu 16.04

  • Reddit: Changing systemd user with drop-in replacement for transmission-daemon not working

  • Stack-Exchange: Changing systemd user with drop-in replacement for transmission-daemon not working


Optional/Additional Information regarding permissions and package updates:

Note: The following is likely only relevant for Upstart and SysV init systems only

Changing Permissions on Transmission's configuration files

If you are not using systemd init system you may now need to change the permissions for Transmission's Configuration files from user=debian-transmission to user=some_user and from group=debian-transmission to group=some_group.

  1. Check the location of your Transmission Configuration Directory. You can find it mentioned in the /etc/default/transmission-daemon file as a line like so:

    CONFIG_DIR="/var/lib/transmission-daemon/info"
    
  2. So assuming your Configuration Directory is /var/lib/transmission-daemon/info, change ownership of configuration files:

    sudo chown some_user:some_group /var/lib/transmission-daemon/downloads
    sudo chown some_user:some_group /var/lib/transmission-daemon/info
    sudo chown some_user:some_group /var/lib/transmission-daemon/info/blocklists
    sudo chown some_user:some_group /var/lib/transmission-daemon/info/dht.dat
    sudo chown some_user:some_group /var/lib/transmission-daemon/info/resume
    sudo chown some_user:some_group /var/lib/transmission-daemon/info/torrents
    
  3. Change ownership of other files:

    sudo chown :some_group /etc/transmission-daemon
    sudo chown some_user:some_group /etc/transmission-daemon/settings.json
    

Extra Information (updating Transmission):

Because you changed the default user you may find that after updating Transmission using the repository (eg: apt-get upgrade) the transmission daemon is no longer running.

Running "sudo apt-get -f install" give the following error:

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up transmission-daemon (2.84-0ubuntu0.12.04.1) ...
 * Starting bittorrent daemon transmission-daemon
invoke-rc.d: initscript transmission-daemon, action "start" failed.
dpkg: error processing transmission-daemon (--configure):
 subprocess installed post-installation script returned error exit status 255
Errors were encountered while processing:
 transmission-daemon
E: Sub-process /usr/bin/dpkg returned an error code (1)

The reason the daemon fails to start ("invoke-rc.d: initscript transmission-daemon, action "start" failed.") is because we changed permissions from "debian-transmission" to "some_user" and after the update these got reset. So to fix just do the following:

  1. Stop Daemon and Edit config file:

    sudo service transmission-daemon stop
    sudo nano /etc/init.d/transmission-daemon
    

    ...and change USER=some_user to USER=debian-transmission

  2. Re-try fixing update by running:

    sudo apt-get -f install
    
  3. If the update succeeds the Transmission daemon should now be running. You can now follow steps above to change user/group again.

Solution 3:

This is not the complete story. Apart from changing

setgid <groupname>

and

setuid <username>

in

/etc/init/transmission-daemon.conf

you also need to change the permissions of the config file of transmission-daemon. Otherwise it won't be able to rewrite settings to this file and the daemon will restart until upstart thinks it had enough chances (init: transmission-daemon respawning too fast, stopped)

sudo chown <user>:<group> /etc/transmission-daemon/settings.json
sudo chown -R <user>:<group> /var/lib/transmission-daemon/ 

Solution 4:

As of upstart v1.4, setuid and setgid are supported natively in config file:

setgid <groupname>

and

setuid <username>

Before v1.4 you can use this (as described here):

exec start-stop-daemon --start -c {user} --exec {command}

Solution 5:

On systems using systemd, the file you want to edit may actually be:

/etc/systemd/system/multi-user.target.wants/transmission-daemon.service

Follow up editing with:

sudo systemctl daemon-reload