Rename existing user oldname to newname.
Which command is appropriate?
usermod -l NEW_LOGIN OLD_LOGIN changes an existing login name. The home-directory name does not change automatically.
Detailed explanation
usermod -d newname oldnameIncorrect. -d changes the home-directory path.
Incorrect. -d changes the home-directory path.
usermod -g newname oldnameIncorrect. -g changes the primary group.
Incorrect. -g changes the primary group.
usermod -l newname oldnameCorrect. It changes oldname to newname.
Correct. It changes oldname to newname.
usermod -s newname oldnameIncorrect. -s changes the login shell.
Incorrect. -s changes the login shell.
Try it yourself
An example you can run in a temporary verification environment.
usermod --help | grep -E -- '-l,|--login'Expected result
新しいログイン名を示す説明行Key points
- -l means login name
- It changes an existing user
- Home path needs separate handling
Notes
- Environment: shadow-utils usermod help / 状態変更なし
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.