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
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
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
Jan 6 at 14:49
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
Jan 6 at 19:41
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
#!/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
edited Jan 6 at 13:24


Kulfy
4,30651442
4,30651442
asked Jan 6 at 13:10


vishnu prajapativishnu prajapati
111
111
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
Jan 6 at 14:49
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
Jan 6 at 19:41
add a comment |
1
You might want to investigate thenewusers
command ("update and create new users in batch")
– steeldriver
Jan 6 at 14:49
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
Jan 6 at 19:41
1
1
You might want to investigate the
newusers
command ("update and create new users in batch")– steeldriver
Jan 6 at 14:49
You might want to investigate the
newusers
command ("update and create new users in batch")– steeldriver
Jan 6 at 14:49
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
Jan 6 at 19:41
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
Jan 6 at 19:41
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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
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
});
}
});
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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
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 Jan 6 at 18:40


wizzwizz4
1176
1176
answered Jan 6 at 13:19


PerlDuckPerlDuck
5,86111333
5,86111333
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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
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
Jan 6 at 13:55
@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
Jan 6 at 13:55
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
Good distinction. I didn't spot that :)
– vidarlo
Jan 6 at 14:10
add a comment |
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.
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
Jan 6 at 14:49
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
Jan 6 at 19:41