Why is there a different result when running as user1 and su - user1 -c âcommandâ?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
When running as user1 in the same directory (/home/user1/WWW)
[user1@server1 WWW (master)]# touch c
Creates the file c inside the directory.
[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"
gives the error
touch: cannot touch `c': Permission denied
Why can this be?
sudo group su
 |Â
show 1 more comment
up vote
0
down vote
favorite
When running as user1 in the same directory (/home/user1/WWW)
[user1@server1 WWW (master)]# touch c
Creates the file c inside the directory.
[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"
gives the error
touch: cannot touch `c': Permission denied
Why can this be?
sudo group su
@Kusalananda yes the directory is owned byuser1:apache
. I would suspect the first case would also fail when that was not true.
â Thomas Moors
Aug 15 at 13:16
3
If your remove the-
from the command and dosu user1 -c ...
? With-
you do a full login, and may end up in another directory than the directory you're currently in.
â Kusalananda
Aug 15 at 13:21
@steeldriver That's what I thought. But why woulduser1
not be able to touchc
in their home directory. Is there already a file owned by another user there?
â Kusalananda
Aug 15 at 13:22
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:su - user1 -c
changed the current working directory!
â Thomas Moors
Aug 15 at 13:25
... and that file inuser1
's home directory is owned by another user?
â Kusalananda
Aug 15 at 13:26
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When running as user1 in the same directory (/home/user1/WWW)
[user1@server1 WWW (master)]# touch c
Creates the file c inside the directory.
[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"
gives the error
touch: cannot touch `c': Permission denied
Why can this be?
sudo group su
When running as user1 in the same directory (/home/user1/WWW)
[user1@server1 WWW (master)]# touch c
Creates the file c inside the directory.
[root@server1 WWW (master) ACCEPTATIE SERVER]# su - user1 -c "touch c"
gives the error
touch: cannot touch `c': Permission denied
Why can this be?
sudo group su
sudo group su
asked Aug 15 at 13:13
Thomas Moors
12410
12410
@Kusalananda yes the directory is owned byuser1:apache
. I would suspect the first case would also fail when that was not true.
â Thomas Moors
Aug 15 at 13:16
3
If your remove the-
from the command and dosu user1 -c ...
? With-
you do a full login, and may end up in another directory than the directory you're currently in.
â Kusalananda
Aug 15 at 13:21
@steeldriver That's what I thought. But why woulduser1
not be able to touchc
in their home directory. Is there already a file owned by another user there?
â Kusalananda
Aug 15 at 13:22
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:su - user1 -c
changed the current working directory!
â Thomas Moors
Aug 15 at 13:25
... and that file inuser1
's home directory is owned by another user?
â Kusalananda
Aug 15 at 13:26
 |Â
show 1 more comment
@Kusalananda yes the directory is owned byuser1:apache
. I would suspect the first case would also fail when that was not true.
â Thomas Moors
Aug 15 at 13:16
3
If your remove the-
from the command and dosu user1 -c ...
? With-
you do a full login, and may end up in another directory than the directory you're currently in.
â Kusalananda
Aug 15 at 13:21
@steeldriver That's what I thought. But why woulduser1
not be able to touchc
in their home directory. Is there already a file owned by another user there?
â Kusalananda
Aug 15 at 13:22
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:su - user1 -c
changed the current working directory!
â Thomas Moors
Aug 15 at 13:25
... and that file inuser1
's home directory is owned by another user?
â Kusalananda
Aug 15 at 13:26
@Kusalananda yes the directory is owned by
user1:apache
. I would suspect the first case would also fail when that was not true.â Thomas Moors
Aug 15 at 13:16
@Kusalananda yes the directory is owned by
user1:apache
. I would suspect the first case would also fail when that was not true.â Thomas Moors
Aug 15 at 13:16
3
3
If your remove the
-
from the command and do su user1 -c ...
? With -
you do a full login, and may end up in another directory than the directory you're currently in.â Kusalananda
Aug 15 at 13:21
If your remove the
-
from the command and do su user1 -c ...
? With -
you do a full login, and may end up in another directory than the directory you're currently in.â Kusalananda
Aug 15 at 13:21
@steeldriver That's what I thought. But why would
user1
not be able to touch c
in their home directory. Is there already a file owned by another user there?â Kusalananda
Aug 15 at 13:22
@steeldriver That's what I thought. But why would
user1
not be able to touch c
in their home directory. Is there already a file owned by another user there?â Kusalananda
Aug 15 at 13:22
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:
su - user1 -c
changed the current working directory!â Thomas Moors
Aug 15 at 13:25
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:
su - user1 -c
changed the current working directory!â Thomas Moors
Aug 15 at 13:25
... and that file in
user1
's home directory is owned by another user?â Kusalananda
Aug 15 at 13:26
... and that file in
user1
's home directory is owned by another user?â Kusalananda
Aug 15 at 13:26
 |Â
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
When you do su - username
you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c
in this way, you therefore try to run that command in the user's home directory.
Instead, drop the -
from the command line:
su user1 -c "touch c"
This would execute touch c
as user1
in the current directory.
Speculation:
The original su -
command failed because there is already a file called c
in user1
's home directory owned by another user.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
When you do su - username
you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c
in this way, you therefore try to run that command in the user's home directory.
Instead, drop the -
from the command line:
su user1 -c "touch c"
This would execute touch c
as user1
in the current directory.
Speculation:
The original su -
command failed because there is already a file called c
in user1
's home directory owned by another user.
add a comment |Â
up vote
4
down vote
accepted
When you do su - username
you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c
in this way, you therefore try to run that command in the user's home directory.
Instead, drop the -
from the command line:
su user1 -c "touch c"
This would execute touch c
as user1
in the current directory.
Speculation:
The original su -
command failed because there is already a file called c
in user1
's home directory owned by another user.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
When you do su - username
you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c
in this way, you therefore try to run that command in the user's home directory.
Instead, drop the -
from the command line:
su user1 -c "touch c"
This would execute touch c
as user1
in the current directory.
Speculation:
The original su -
command failed because there is already a file called c
in user1
's home directory owned by another user.
When you do su - username
you perform a full login as that user, meaning that you are transferred to the user's home directory. When executing touch c
in this way, you therefore try to run that command in the user's home directory.
Instead, drop the -
from the command line:
su user1 -c "touch c"
This would execute touch c
as user1
in the current directory.
Speculation:
The original su -
command failed because there is already a file called c
in user1
's home directory owned by another user.
edited Aug 15 at 13:33
answered Aug 15 at 13:27
Kusalananda
106k14209327
106k14209327
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462745%2fwhy-is-there-a-different-result-when-running-as-user1-and-su-user1-c-command%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@Kusalananda yes the directory is owned by
user1:apache
. I would suspect the first case would also fail when that was not true.â Thomas Moors
Aug 15 at 13:16
3
If your remove the
-
from the command and dosu user1 -c ...
? With-
you do a full login, and may end up in another directory than the directory you're currently in.â Kusalananda
Aug 15 at 13:21
@steeldriver That's what I thought. But why would
user1
not be able to touchc
in their home directory. Is there already a file owned by another user there?â Kusalananda
Aug 15 at 13:22
@steeldriver that is the correct identification of my problem and is solved now. So conclusion for everyone coming here via google:
su - user1 -c
changed the current working directory!â Thomas Moors
Aug 15 at 13:25
... and that file in
user1
's home directory is owned by another user?â Kusalananda
Aug 15 at 13:26