Change daemon user

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
joachim
Posts: 1
Joined: Mon Jun 10, 2013 11:17 am

Change daemon user

Post by joachim »

Hi,

I've just upgraded my Ubuntu distro from 12.04 LTS to 13.04. After the upgrade, I realized that transmission-daemon is now running as the user "debian-transmission", and not as the user "joachim" that I wanted it to run as.

I looked in the init.d/transmission-daemon, but can't find the USER variable anymore. I tried to create it, but it doesn't seem to work.

Is it possible to run transmission as another user in Ubuntu 13.04?

Thank you for your time,
Joachim
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: Change daemon user

Post by blacke4dawn »

Didn't Ubuntu change to upstart for init handling, and thus hardly use the init.d directory anymore?

Anyway, if they still use an init-script for Transmission then technically it is still be possible but maybe not as straightforward as it was before. I believe Ubuntu (and other .deb based distros) use the /etc/default(s) directory for user supplied config changes to init-scripts, it should source it from the init-script so look for a line that starts with either "source" or just a dot and then a file under /etc/<some folder>.

By the way, this is an issue with Ubuntu them self since they are the ones who put together that specific package and the init-script in it, not the Transmission devs.
DaftHonk
Posts: 1
Joined: Sun Jul 21, 2013 12:03 am

Re: Change daemon user

Post by DaftHonk »

The solution to this is quite simple, though it took me quite a few hours of searching to figure it out.

1. Stop transmission:

Code: Select all

sudo service transmission-daemon stop
2. Open the transmission-daemon configuration file:

Code: Select all

sudo gedit /etc/init/transmission-daemon.conf
Change the userid from debian-transmission to the desired user (USER):

Code: Select all

setuid debian-transmission

Code: Select all

ssetuid USER
3. Change ownership of the settings.json file and the contents of /var/lib/transmission-daemon:

Code: Select all

sudo chown USER:USER settings.json*

Code: Select all

sudo chown -R USER:USER /var/lib/transmission-daemon/downloads

Code: Select all

sudo chown -R USER:USER /var/lib/transmission-daemon/info
4. Start transmission:

Code: Select all

sudo service transmission-daemon start
And that should be it. My transmission is now running successfully as the xbmc user on my HTPC.
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: Change daemon user

Post by blacke4dawn »

DaftHonk wrote:3. Change ownership of the settings.json file and the contents of /var/lib/transmission-daemon:

Code: Select all

sudo chown USER:USER settings.json*

Code: Select all

sudo chown -R USER:USER /var/lib/transmission-daemon/downloads

Code: Select all

sudo chown -R USER:USER /var/lib/transmission-daemon/info
I would actually do:

Code: Select all

sudo chown -R USER:USER /var/lib/transmission-daemon
Since in your examples you don't include the resume directory (unless that is the info-directory, which is not the standard name) and thus it would have a hard time keeping existing and new torrents "up to date". You also have a little more in there, like dht.dat and possible blocklists.
rickiyo
Posts: 1
Joined: Sun Apr 03, 2016 4:23 pm

Re: Change daemon user

Post by rickiyo »

Hi, I know this post is old, but this is my "go-to-post" for whenever I need install transmission and need to change it's user to something other than debian-transmission. I recently updated transmission and nothing worked at all, spent hours trying to fix it and decided to erase everything and start from scratch.

Here's the thing, transmission never created the "transmission-daemon.conf" file. I thought that maybe they changed the file location so I searched my entire system for it, and nothing came up.

Code: Select all

/etc/init/transmission-daemon.conf
After hours of countless google searches, I finally came to a close solution. Edit /etc/init.d/transmission-daemon and change the USER to the one you want

Code: Select all

NAME=transmission-daemon
DAEMON=/usr/bin/$NAME
USER=joe
STOP_TIMEOUT=30
Im no expert so I can not assure you that this IS the solution but since I did it, it has been writing the files with the correct user and everything has been working smoothly. Also DO NOT forget to change the folder and settings.json permissions as mentioned on the posts above.
sampi
Posts: 1
Joined: Sat May 20, 2017 7:10 pm

Re: Change daemon user

Post by sampi »

Besides trying all of the above fixes, I needed to change "debian-transmission" to the uid I wanted in "/lib/systemd/system/transmission-daemon.service" as well!

I hope this helps! I'm on Ubuntu 16.04 LTS
crmnbg
Posts: 1
Joined: Mon Jul 24, 2017 3:27 pm

Re: Change daemon user

Post by crmnbg »

since this is also my go to post and i will always forget this abnd search for a solution

debian and ubuntu users need to edit /lib/systemd/system/transmission-daemon.service and the config file will be read from ~/.config/transmission-daemon/
MrPotatoHead
Posts: 2
Joined: Tue Jan 02, 2018 5:12 pm

Re: Change daemon user

Post by MrPotatoHead »

Updated for Ubuntu 16.04.3 LTS server.

How to change the Transmission daemon's username

0) Elevate your login to sudo

Code: Select all

sudo -i
Now you don't have to type "sudo" at the beginning of every line. :mrgreen:

1) Stop the Transmission service from running in the background. Otherwise, these edits won't stick.

Code: Select all

service transmission-daemon stop
2) Edit first init Transmission configuration file.

Code: Select all

nano /etc/init.d/transmission-daemon
Find line that reads:

Code: Select all

USER=debian-transmission
Edit username to whatever you desire. I'm not going to describe how to create a new user and set permissions as there are various methods. Make sure it's an existing user! It should be a system user. If you're using Webmin make sure the "No login allowed" box is checked. That prevents this user from having terminal access and getting elevated privileges (to root). You want to segment the control of this user just to Transmission.

3) Edit 2nd init Transmission configuration file.

Code: Select all

nano /etc/init/transmission-daemon.conf
Find these two lines. Change both the user ID (uid) and group ID (gid) as required. The user must already exist as a system user. The user group must already exist and the username must belong to it. I'm not certain if the user group must be the username's primary user group or not, but I strongly recommend using the primary group ID because I know some processes only look at the primary GID. You are less likely to have a problem if you follow that methodology.

Code: Select all

setuid debian-transmission
setgid debian-transmission
4) Edit the daemon service configuration file.

Code: Select all

nano /lib/systemd/system/transmission-daemon.service
Find this section and modify the username (default = debian-transmission).

Code: Select all

[Service]
User=debian-transmission
5) Modify file permissions. Examine the current file or directory owners.

Code: Select all

ls /etc/trans* -lh
Look for the owner of the transmission-daemon directory.

Code: Select all

drwxrwsr-x   2 debian-transmission vpn    4.0K Jan  2 10:18 transmission-daemon
Then check the files and folders inside.

Code: Select all

ls /etc/transmission-daemon -lh
The defaults are:

Code: Select all

total 8.0K
-rw-r--r-- 1 debian-transmission debian-transmission  303 Feb 20  2017 README.json
-rw------- 1 debian-transmission debian-transmission 2.4K Jan  2 10:18 settings.json
If the owners need to be changed, the command is

Code: Select all

chown debian-transmission:debian-transmission /etc/transmission-daemon -R
The command above will also set ownership correctly of any underlying files or sub-directories.

Now check the library file permissions:

Code: Select all

ls /var/lib/transmission-daemon -lhR
If all the files and directories don't have permission set to your desired Transmission owner ID and group ID, you need to correct them. Change the username/group name to whatever you are using.

Code: Select all

chown debian-transmission:debian-transmission /var/lib/transmission-daemon -R
6) Reboot to be sure all the user/group name changes get picked up from the config files.

Code: Select all

reboot
7) After the server restarts, login verify the Transmission daemon (background) process is running and no errors were encountered during initialization.

Code: Select all

sudo service transmission-daemon status
You should see something like this:

Code: Select all

●transmission-daemon.service - Transmission BitTorrent Daemon
   Loaded: loaded (/lib/systemd/system/transmission-daemon.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-01-02 10:18:01 CST; 1min 54s ago
 Main PID: 1101 (transmission-da)
   Status: "Idle."
    Tasks: 4
   Memory: 1.1M
      CPU: 42ms
   CGroup: /system.slice/transmission-daemon.service
           └─1101 /usr/bin/transmission-daemon -f --log-error

Jan 02 10:18:00 mediaserver systemd[1]: Starting Transmission BitTorrent Daemon...
Jan 02 10:18:01 mediaserver systemd[1]: Started Transmission BitTorrent Daemon.
You should see the first 15 characters of the username running the process after the process ID (PID) number. Is it your expected username? If you see any errors, address them. Errors are typically caused by file permission conflicts.

If the daemon is not active, you made a mistake in one of the configuration files.

Here's another way to verify the user running the daemon process:

Code: Select all

ps -ef | egrep '(transmission)' | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'
You'll get output that only shows seven characters of the username. If the name is longer, there will be a '+' symbol after the first seven characters. For example, if the user running Transmission is still debian-transmission (the default username), the output will be

Code: Select all

debian-+
If you verified your code changes and still don't see the output you expected, verify your username and group names in the CLI or in Webmin, and start the process over again.

PLEASE NOTE if you change the Transmission username, any subsequent files downloaded by Transmission will be owned by the new user and its primary group ID. You will need to take that into consideration and at the very least you'll want to be certain other processes (e.g. Sonarr) are able to access and manipulate the downloaded files. Don't forget to set file and directory permissions of Transmission's download directories to restrict access by group (e.g. 755 or 775), and ensure other programs you want to be capable of manipulating Transmission files are also a member of the Transmission daemon's new primary group id. They don't need to have their primary group ID changed. Simply add those users to the same group but as secondary group members. This can be accomplished easily via the Webmin GUI.
MrPotatoHead
Posts: 2
Joined: Tue Jan 02, 2018 5:12 pm

Re: Change daemon user

Post by MrPotatoHead »

One more thing.... the correct command to restart a stopped Transmission daemon in Ubuntu is

Code: Select all

service transmission-daemon restart
NOT

Code: Select all

service transmission-daemon start
renatorattes
Posts: 1
Joined: Tue Jan 16, 2018 6:06 pm

Re: Change daemon user

Post by renatorattes »

After these steps I have a RPC problem:

Code: Select all

Jan 16 18:04:20 raspberrypi systemd[1]: Starting Transmission BitTorrent Daemon...
Jan 16 18:04:20 raspberrypi systemd[1]: Started Transmission BitTorrent Daemon.
Jan 16 18:04:21 raspberrypi transmission-daemon[1415]: [2018-01-16 18:04:21.983] UDP Failed to 
Jan 16 18:04:21 raspberrypi transmission-daemon[1415]: [2018-01-16 18:04:21.984] UDP Failed to 

Code: Select all

403: Forbidden

Unauthorized IP Address.

Either disable the IP address whitelist or add your address to it.

If you're editing settings.json, see the 'rpc-whitelist' and 'rpc-whitelist-enabled' entries.

If you're still using ACLs, use a whitelist instead. See the transmission-daemon manpage for details.
I see my rpc-whitelist but without any changes.

Code: Select all

"rpc-password": "raspberry",
    "rpc-port": 9091,
    "rpc-url": "/transmission/",
    "rpc-username": "pi",
    "rpc-whitelist": "*.*.*.*",
    "rpc-whitelist-enabled": true,
    "scrape-paused-torrents-enabled": true,
    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
    "seed-queue-enabled": false,
    "seed-queue-size": 10,
    "speed-limit-down": 100,
    "speed-limit-down-enabled": false,
    "speed-limit-up": 100,
    "speed-limit-up-enabled": false,
    "start-added-torrents": true,                                          
    "trash-original-torrent-files": false,
    "umask": 2,
    "upload-limit": 100,
    "upload-limit-enabled": 0,
    "upload-slots-per-torrent": 14,
    "utp-enabled": true
}
Can you help me?
kipouros
Posts: 6
Joined: Mon Mar 13, 2017 2:30 pm

Re: Change daemon user

Post by kipouros »

Same here, after the user change I have the rpc denied issue as described above.

I am really getting tired with this, every couple of months, version change, nothing works and we need to dig into all these things that I care not to memorize and have to dig the forums every time...

Also the answers are really really slow...

Very dissappointed...
kipouros
Posts: 6
Joined: Mon Mar 13, 2017 2:30 pm

Re: Change daemon user

Post by kipouros »

Hey @renatorattes I found the problem.

your settings.json file is owned and readble only by the old user (debian-transmission)

Change permissions for the new user you assigned and everything will be back to normal.
kipouros
Posts: 6
Joined: Mon Mar 13, 2017 2:30 pm

Re: Change daemon user

Post by kipouros »

And the /var/lib/transmission-daemon/.config folder permissions
kipouros
Posts: 6
Joined: Mon Mar 13, 2017 2:30 pm

Re: Change daemon user

Post by kipouros »

No... Sorry... I was too fast to post... Nothing works. something about not being able to modify devices.list
Can't be arsed anymore. Too tired. Most probably going to deluge...
marc
Posts: 1
Joined: Thu Feb 22, 2018 8:57 pm

Re: Change daemon user

Post by marc »

On Debian tranmission-daemon seems to persist in wanting 'debian-transmission' as a user. I followed all advice above, but transmission-daemon wouldn't start.

How I did get it to work:

Code: Select all

# vipw
Run vipw and:
1. Make sure the user 'debian-transmission' does not exist (I had deleted it);
2. Duplicate the user that you want transmission-daemon to use (in my case: 'transmission');
3. Rename the duplicate's username to 'debian-transmission'.

Code: Select all

transmission:x:128:139::/var/lib/transmission-daemon:/bin/false
debian-transmission:x:128:139::/var/lib/transmission-daemon:/bin/false
You now have 2 usernames pointing to the same userID. After this I ran vipw -s and repeated the above.

Code: Select all

# vipw -s
Post Reply