0

I have a question regarding changing the home folder for a user on the system. I was thinking I could do something like:

new_folder_name="$2"
user_name="$3"
mkdir /home/$new_folder_name
usermod -d -m /home/$new_folder_name/$user_name

This unfortunately did not work and now I feel kinda lost. Anyone have some advice on how to do this?

I used mkdir /home/$2 chown $3:$3 /home/$2 chmod 700 /home/$2 usermod --home /home/$2 $3 instead, which works, but it prints chown: invalid group:username:username afterwards, why is that?

1
  • Please define "did not work". What happened? What did you expect? Commented Feb 20, 2020 at 10:55

3 Answers 3

0

At first you must create path /home/$2/$3. You may execute, for example, mkdir -p /home/$2/$3 Then you need run chmod username:username /home/$2/$3 After that you may run usermod -d -m /home/$2/$3 I think is nessessery to run chown 750 /home/$2/$3

1
  • I dont get the username:username part, do I change that to the username of the user that I wish to move, for example: chmod $3:$3 /home/$2/$3 ?
    – Fredrik
    Commented Feb 20, 2020 at 11:30
0

It looks like you missed a space in usermod, you should also quote your variables. You will also have to move the data (probably instead of creating the empty directory).

0

There is a syntax error in usermod

Try as

usermod -d /home/$new_folder_name -m $user_name

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .