← Back to list

[SOLVED] nohup'ing a sudo command — doesn't seem to work

Ted James · 2024-09-04 04:39 · 0 claps · 1.0 min read
#bash #background-process #sudo #nohup
Open on Medium ↗
Wiki topics: 🥊 · Combat Sports

nohup’ing a sudo command — doesn’t seem to work

I’ve read this and several other articles but I can’t figure this out. This is what I’ve put together:

  1. sudo nohup or nohup sudo (I've tried both) the command without the background & (so you can enter your password before detaching it)
  2. Enter the password
  3. ^Z then bg
  4. disown the pid (doesn't work for some reason)
  5. Log out

Here’s the output:

[user@localhost ~]$ nohup sudo dd if=/dev/zero of=/dev/sda bs=1M
nohup: ignoring input and appending output to ‘nohup.out’
[sudo] password for user: 
^Z
[1]+  Stopped                 nohup sudo dd if=/dev/zero of=/dev/sda bs=1M
[user@localhost ~]$ bg
[1]+ nohup sudo dd if=/dev/zero of=/dev/sda bs=1M &
[user@localhost ~]$ sudo ps | grep dd
 2458 pts/32   00:00:00 dd
[user@localhost ~]$ disown 2458
-bash: disown: 2458: no such job
[user@localhost ~]$ logout
Connection to [server] closed.
$ remote
Last login: Mon Feb  3 11:32:59 2014 from [...]
[user@localhost ~]$ sudo ps | grep dd
[sudo] password for user: 
[user@localhost ~]$

So the process is gone. I’ve tried a few other combinations with no success. Any ideas to make this work?

Solution

Use the -b option to sudo to instruct it to run the given command in the background. Job control doesn't work because the nohup process is not a child of the current shell, but of the sudo process.

sudo -b nohup dd if=/dev/zero of=/dev/sda bs=1M

Answered By — chepner

Answer Checked By — Terry (FixIt Volunteer)

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0


메타데이터
post_id
a8cd59681cd5
slug
solved-nohup-39-ing-a-sudo-command-doesn-39-t-seem-to-work-a8cd59681cd5
url
https://medium.com/@fixitblog/solved-nohup-39-ing-a-sudo-command-doesn-39-t-seem-to-work-a8cd59681cd5
canonical_url
https://medium.com/@fixitblog/solved-nohup-39-ing-a-sudo-command-doesn-39-t-seem-to-work-a8cd59681cd5
author_url
https://medium.com/@fixitblog
status
ok
fetched_at
2026-06-27 18:20:27