How to make home directory of existing users?
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read firstname lastname userid
do
sudo useradd -c "${firstname}.${lastname}" -d /home/students/student/"${firstname}.${lastname}" -G students -s /bin/bash "${userid}"
done < hello.csv
bash
New contributor
add a comment |
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read firstname lastname userid
do
sudo useradd -c "${firstname}.${lastname}" -d /home/students/student/"${firstname}.${lastname}" -G students -s /bin/bash "${userid}"
done < hello.csv
bash
New contributor
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago
add a comment |
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read firstname lastname userid
do
sudo useradd -c "${firstname}.${lastname}" -d /home/students/student/"${firstname}.${lastname}" -G students -s /bin/bash "${userid}"
done < hello.csv
bash
New contributor
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read firstname lastname userid
do
sudo useradd -c "${firstname}.${lastname}" -d /home/students/student/"${firstname}.${lastname}" -G students -s /bin/bash "${userid}"
done < hello.csv
bash
bash
New contributor
New contributor
edited Jan 6 at 13:24
Kulfy
3,85841140
3,85841140
New contributor
asked Jan 6 at 13:10
vishnu prajapativishnu prajapati
111
111
New contributor
New contributor
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago
add a comment |
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago
1
1
You might want to investigate the
newusers
command ("update and create new users in batch")– steeldriver
2 days ago
You might want to investigate the
newusers
command ("update and create new users in batch")– steeldriver
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
From the manpage:
-m, --create-home
Create the user's home directory if it does not exist.
The files and directories contained in the skeleton directory
(which can be defined with the -k option) will be copied to
the home directory.
By default, if this option is not specified and CREATE_HOME
is not enabled, no home directories are created.
However, I would strongly suggest to not use a user's real name
for the $HOME directory as you did with -d /home/students/student/"${firstname}.${lastname}"
.
Think of (real) usernames like "John A. Doe".
His $HOME directory would contain a space and that is not exactly userfriendly.
Or someone with a non-latin name. Would not work. Usernames has to match[a-z_][a-z0-9_-]*[$]?
according toman useradd
– vidarlo
Jan 6 at 13:44
1
@vidarlo Not quite. What you say is true for the username (the string you get fromid
or what you need to type when logging in, e.g.pduck
). But the OP uses the real name for the $HOME path, e.g./home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write"$HOME"
instead of just$HOME
and I'm tempted to predict that users will keep asking the OP whycd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.
– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
vishnu prajapati is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107416%2fhow-to-make-home-directory-of-existing-users%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
From the manpage:
-m, --create-home
Create the user's home directory if it does not exist.
The files and directories contained in the skeleton directory
(which can be defined with the -k option) will be copied to
the home directory.
By default, if this option is not specified and CREATE_HOME
is not enabled, no home directories are created.
However, I would strongly suggest to not use a user's real name
for the $HOME directory as you did with -d /home/students/student/"${firstname}.${lastname}"
.
Think of (real) usernames like "John A. Doe".
His $HOME directory would contain a space and that is not exactly userfriendly.
Or someone with a non-latin name. Would not work. Usernames has to match[a-z_][a-z0-9_-]*[$]?
according toman useradd
– vidarlo
Jan 6 at 13:44
1
@vidarlo Not quite. What you say is true for the username (the string you get fromid
or what you need to type when logging in, e.g.pduck
). But the OP uses the real name for the $HOME path, e.g./home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write"$HOME"
instead of just$HOME
and I'm tempted to predict that users will keep asking the OP whycd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.
– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
add a comment |
From the manpage:
-m, --create-home
Create the user's home directory if it does not exist.
The files and directories contained in the skeleton directory
(which can be defined with the -k option) will be copied to
the home directory.
By default, if this option is not specified and CREATE_HOME
is not enabled, no home directories are created.
However, I would strongly suggest to not use a user's real name
for the $HOME directory as you did with -d /home/students/student/"${firstname}.${lastname}"
.
Think of (real) usernames like "John A. Doe".
His $HOME directory would contain a space and that is not exactly userfriendly.
Or someone with a non-latin name. Would not work. Usernames has to match[a-z_][a-z0-9_-]*[$]?
according toman useradd
– vidarlo
Jan 6 at 13:44
1
@vidarlo Not quite. What you say is true for the username (the string you get fromid
or what you need to type when logging in, e.g.pduck
). But the OP uses the real name for the $HOME path, e.g./home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write"$HOME"
instead of just$HOME
and I'm tempted to predict that users will keep asking the OP whycd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.
– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
add a comment |
From the manpage:
-m, --create-home
Create the user's home directory if it does not exist.
The files and directories contained in the skeleton directory
(which can be defined with the -k option) will be copied to
the home directory.
By default, if this option is not specified and CREATE_HOME
is not enabled, no home directories are created.
However, I would strongly suggest to not use a user's real name
for the $HOME directory as you did with -d /home/students/student/"${firstname}.${lastname}"
.
Think of (real) usernames like "John A. Doe".
His $HOME directory would contain a space and that is not exactly userfriendly.
From the manpage:
-m, --create-home
Create the user's home directory if it does not exist.
The files and directories contained in the skeleton directory
(which can be defined with the -k option) will be copied to
the home directory.
By default, if this option is not specified and CREATE_HOME
is not enabled, no home directories are created.
However, I would strongly suggest to not use a user's real name
for the $HOME directory as you did with -d /home/students/student/"${firstname}.${lastname}"
.
Think of (real) usernames like "John A. Doe".
His $HOME directory would contain a space and that is not exactly userfriendly.
edited 2 days ago
wizzwizz4
1176
1176
answered Jan 6 at 13:19
PerlDuckPerlDuck
5,52411231
5,52411231
Or someone with a non-latin name. Would not work. Usernames has to match[a-z_][a-z0-9_-]*[$]?
according toman useradd
– vidarlo
Jan 6 at 13:44
1
@vidarlo Not quite. What you say is true for the username (the string you get fromid
or what you need to type when logging in, e.g.pduck
). But the OP uses the real name for the $HOME path, e.g./home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write"$HOME"
instead of just$HOME
and I'm tempted to predict that users will keep asking the OP whycd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.
– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
add a comment |
Or someone with a non-latin name. Would not work. Usernames has to match[a-z_][a-z0-9_-]*[$]?
according toman useradd
– vidarlo
Jan 6 at 13:44
1
@vidarlo Not quite. What you say is true for the username (the string you get fromid
or what you need to type when logging in, e.g.pduck
). But the OP uses the real name for the $HOME path, e.g./home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write"$HOME"
instead of just$HOME
and I'm tempted to predict that users will keep asking the OP whycd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.
– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
Or someone with a non-latin name. Would not work. Usernames has to match
[a-z_][a-z0-9_-]*[$]?
according to man useradd
– vidarlo
Jan 6 at 13:44
Or someone with a non-latin name. Would not work. Usernames has to match
[a-z_][a-z0-9_-]*[$]?
according to man useradd
– vidarlo
Jan 6 at 13:44
1
1
@vidarlo Not quite. What you say is true for the username (the string you get from
id
or what you need to type when logging in, e.g. pduck
). But the OP uses the real name for the $HOME path, e.g. /home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write "$HOME"
instead of just $HOME
and I'm tempted to predict that users will keep asking the OP why cd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.– PerlDuck
2 days ago
@vidarlo Not quite. What you say is true for the username (the string you get from
id
or what you need to type when logging in, e.g. pduck
). But the OP uses the real name for the $HOME path, e.g. /home/students/student/Perl.Duck
. Here, anything that is a valid filename is allowed but when it contains weird characters you always have to write "$HOME"
instead of just $HOME
and I'm tempted to predict that users will keep asking the OP why cd /home/students/student/John A. Doe
won't take them to their home directory but complain about cd: too many arguments instead.– PerlDuck
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
Good distinction. I didn't spot that :)
– vidarlo
2 days ago
add a comment |
vishnu prajapati is a new contributor. Be nice, and check out our Code of Conduct.
vishnu prajapati is a new contributor. Be nice, and check out our Code of Conduct.
vishnu prajapati is a new contributor. Be nice, and check out our Code of Conduct.
vishnu prajapati is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107416%2fhow-to-make-home-directory-of-existing-users%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You might want to investigate the
newusers
command ("update and create new users in batch")– steeldriver
2 days ago
Welcome to Ask Ubuntu! What’s your question? What are you trying to achieve? (Please edit your post when you want to clarify something or add information. It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons.) Thanks.
– David Foerster
2 days ago