Skip to main content
added 16 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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 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.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

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 command failed because there is already a file called c in user1's home directory owned by another user.