How to change the Home directory of the currently logged In user

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
10
down vote

favorite
5












I am currently logged in into a CentOS server and I would like to change my home directory from /home/myuserName/ to /var/www/html/



I tried the below command :



> sudo usermod -d /var/www/html myuserName


But this gives me an error:



usermod: user myUserName is currently logged in









share|improve this question



















  • 2




    I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
    – Archemar
    Feb 4 '16 at 8:23










  • That helps, But i would like to change my home directory permanently, not for just the current session.
    – Mohan
    Feb 4 '16 at 8:28














up vote
10
down vote

favorite
5












I am currently logged in into a CentOS server and I would like to change my home directory from /home/myuserName/ to /var/www/html/



I tried the below command :



> sudo usermod -d /var/www/html myuserName


But this gives me an error:



usermod: user myUserName is currently logged in









share|improve this question



















  • 2




    I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
    – Archemar
    Feb 4 '16 at 8:23










  • That helps, But i would like to change my home directory permanently, not for just the current session.
    – Mohan
    Feb 4 '16 at 8:28












up vote
10
down vote

favorite
5









up vote
10
down vote

favorite
5






5





I am currently logged in into a CentOS server and I would like to change my home directory from /home/myuserName/ to /var/www/html/



I tried the below command :



> sudo usermod -d /var/www/html myuserName


But this gives me an error:



usermod: user myUserName is currently logged in









share|improve this question















I am currently logged in into a CentOS server and I would like to change my home directory from /home/myuserName/ to /var/www/html/



I tried the below command :



> sudo usermod -d /var/www/html myuserName


But this gives me an error:



usermod: user myUserName is currently logged in






linux centos users home






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 4 '16 at 11:36









Jeff Schaller

37.5k1052121




37.5k1052121










asked Feb 4 '16 at 8:05









Mohan

151115




151115







  • 2




    I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
    – Archemar
    Feb 4 '16 at 8:23










  • That helps, But i would like to change my home directory permanently, not for just the current session.
    – Mohan
    Feb 4 '16 at 8:28












  • 2




    I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
    – Archemar
    Feb 4 '16 at 8:23










  • That helps, But i would like to change my home directory permanently, not for just the current session.
    – Mohan
    Feb 4 '16 at 8:28







2




2




I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
– Archemar
Feb 4 '16 at 8:23




I am unsure what you meant, HOME=/var/www/html will change for the session your home dir.
– Archemar
Feb 4 '16 at 8:23












That helps, But i would like to change my home directory permanently, not for just the current session.
– Mohan
Feb 4 '16 at 8:28




That helps, But i would like to change my home directory permanently, not for just the current session.
– Mohan
Feb 4 '16 at 8:28










5 Answers
5






active

oldest

votes

















up vote
12
down vote













short answer : you can't.



long answer:



HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir.



The proper way to change home dir for joe is :



  • have joe log off.

  • use usermod -d /new/home joe to change home dir for subsequent session.

Once session is run, you must do two things:



  • edit $HOME to change home dir for session (to be repeated on all active session).

  • use sudo vipw to edit home dir for next wession

Also, be aware you might have an issue with permissions/ownship on /var/www/html






share|improve this answer




















  • edit /etc/passwd always worked for me. See @7171u below
    – jeffmcneill
    Mar 30 '17 at 11:35










  • editing /etc/passwd without logoff/logon ?
    – Archemar
    Mar 30 '17 at 12:02










  • editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
    – jeffmcneill
    Mar 31 '17 at 9:12

















up vote
7
down vote













The usermod command won't work if you're logged in with the user you are trying to make changes on.



From the manual page on usermod it says:




CAVEATS
usermod will not allow you to change the name of a user who is logged in. You must make certain that the named user is not executing
any processes when this command is being executed if the user's
numerical
user ID is being changed. You must change the owner of any crontab files manually. You must change the owner of any at jobs
manually. You must make any changes involving NIS on the NIS server.




Try logging in with a different user and running the command again.



If that isn't possible then you can manually edit the /etc/passwd file (which is actually what the usermod command is doing). If you do that make sure you back the file up in case you inadvertently do something silly.






share|improve this answer





























    up vote
    4
    down vote













    You need to edit the /etc/passwd file to change home directory of users that are currently logged in.



    Edit the /etc/passwd with sudo vipw and change home directory of the user.



    vipw highly recommended other than vim or other editors since vipw will set lock to prevent any data corruption.






    share|improve this answer



























      up vote
      0
      down vote













      A couple possible workarounds, depending on what you're hoping to solve:



      Option 1. Add HOME=/var/www/html to your .bashrc



      Option 2. Rename /home/myusername and then create a symlink to the desired directory.



      mv /home/myusername /home/myusername-old
      ln -s /var/www/html /home/myusername





      share|improve this answer






















      • bad habbit. after that, myusername-old can not be used by other user
        – GeoMint
        Jun 3 at 9:52

















      up vote
      -1
      down vote













      You can only do this temporarily. This means that every time you login as that user you have to run this one command:



      export HOME=/var/www/html


      This way, you can make most applications think that your home directory is whatever location you use above.



      ~ will also start to point to /var/www/html.



      The applications this worked with for me were NPM and Maven.






      share|improve this answer




















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        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',
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        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
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f259791%2fhow-to-change-the-home-directory-of-the-currently-logged-in-user%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        12
        down vote













        short answer : you can't.



        long answer:



        HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir.



        The proper way to change home dir for joe is :



        • have joe log off.

        • use usermod -d /new/home joe to change home dir for subsequent session.

        Once session is run, you must do two things:



        • edit $HOME to change home dir for session (to be repeated on all active session).

        • use sudo vipw to edit home dir for next wession

        Also, be aware you might have an issue with permissions/ownship on /var/www/html






        share|improve this answer




















        • edit /etc/passwd always worked for me. See @7171u below
          – jeffmcneill
          Mar 30 '17 at 11:35










        • editing /etc/passwd without logoff/logon ?
          – Archemar
          Mar 30 '17 at 12:02










        • editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
          – jeffmcneill
          Mar 31 '17 at 9:12














        up vote
        12
        down vote













        short answer : you can't.



        long answer:



        HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir.



        The proper way to change home dir for joe is :



        • have joe log off.

        • use usermod -d /new/home joe to change home dir for subsequent session.

        Once session is run, you must do two things:



        • edit $HOME to change home dir for session (to be repeated on all active session).

        • use sudo vipw to edit home dir for next wession

        Also, be aware you might have an issue with permissions/ownship on /var/www/html






        share|improve this answer




















        • edit /etc/passwd always worked for me. See @7171u below
          – jeffmcneill
          Mar 30 '17 at 11:35










        • editing /etc/passwd without logoff/logon ?
          – Archemar
          Mar 30 '17 at 12:02










        • editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
          – jeffmcneill
          Mar 31 '17 at 9:12












        up vote
        12
        down vote










        up vote
        12
        down vote









        short answer : you can't.



        long answer:



        HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir.



        The proper way to change home dir for joe is :



        • have joe log off.

        • use usermod -d /new/home joe to change home dir for subsequent session.

        Once session is run, you must do two things:



        • edit $HOME to change home dir for session (to be repeated on all active session).

        • use sudo vipw to edit home dir for next wession

        Also, be aware you might have an issue with permissions/ownship on /var/www/html






        share|improve this answer












        short answer : you can't.



        long answer:



        HOME dir is set in /etc/passwd, 6th field. It is read upon loggin, your shell is started with this home dir.



        The proper way to change home dir for joe is :



        • have joe log off.

        • use usermod -d /new/home joe to change home dir for subsequent session.

        Once session is run, you must do two things:



        • edit $HOME to change home dir for session (to be repeated on all active session).

        • use sudo vipw to edit home dir for next wession

        Also, be aware you might have an issue with permissions/ownship on /var/www/html







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 4 '16 at 9:27









        Archemar

        19.5k93569




        19.5k93569











        • edit /etc/passwd always worked for me. See @7171u below
          – jeffmcneill
          Mar 30 '17 at 11:35










        • editing /etc/passwd without logoff/logon ?
          – Archemar
          Mar 30 '17 at 12:02










        • editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
          – jeffmcneill
          Mar 31 '17 at 9:12
















        • edit /etc/passwd always worked for me. See @7171u below
          – jeffmcneill
          Mar 30 '17 at 11:35










        • editing /etc/passwd without logoff/logon ?
          – Archemar
          Mar 30 '17 at 12:02










        • editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
          – jeffmcneill
          Mar 31 '17 at 9:12















        edit /etc/passwd always worked for me. See @7171u below
        – jeffmcneill
        Mar 30 '17 at 11:35




        edit /etc/passwd always worked for me. See @7171u below
        – jeffmcneill
        Mar 30 '17 at 11:35












        editing /etc/passwd without logoff/logon ?
        – Archemar
        Mar 30 '17 at 12:02




        editing /etc/passwd without logoff/logon ?
        – Archemar
        Mar 30 '17 at 12:02












        editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
        – jeffmcneill
        Mar 31 '17 at 9:12




        editing /etc/passwd for an account that is logged in, and then start a new session with that same account, and it obeys the new home dir. For the already logged in account, that session still has the old home location in the Environment.
        – jeffmcneill
        Mar 31 '17 at 9:12












        up vote
        7
        down vote













        The usermod command won't work if you're logged in with the user you are trying to make changes on.



        From the manual page on usermod it says:




        CAVEATS
        usermod will not allow you to change the name of a user who is logged in. You must make certain that the named user is not executing
        any processes when this command is being executed if the user's
        numerical
        user ID is being changed. You must change the owner of any crontab files manually. You must change the owner of any at jobs
        manually. You must make any changes involving NIS on the NIS server.




        Try logging in with a different user and running the command again.



        If that isn't possible then you can manually edit the /etc/passwd file (which is actually what the usermod command is doing). If you do that make sure you back the file up in case you inadvertently do something silly.






        share|improve this answer


























          up vote
          7
          down vote













          The usermod command won't work if you're logged in with the user you are trying to make changes on.



          From the manual page on usermod it says:




          CAVEATS
          usermod will not allow you to change the name of a user who is logged in. You must make certain that the named user is not executing
          any processes when this command is being executed if the user's
          numerical
          user ID is being changed. You must change the owner of any crontab files manually. You must change the owner of any at jobs
          manually. You must make any changes involving NIS on the NIS server.




          Try logging in with a different user and running the command again.



          If that isn't possible then you can manually edit the /etc/passwd file (which is actually what the usermod command is doing). If you do that make sure you back the file up in case you inadvertently do something silly.






          share|improve this answer
























            up vote
            7
            down vote










            up vote
            7
            down vote









            The usermod command won't work if you're logged in with the user you are trying to make changes on.



            From the manual page on usermod it says:




            CAVEATS
            usermod will not allow you to change the name of a user who is logged in. You must make certain that the named user is not executing
            any processes when this command is being executed if the user's
            numerical
            user ID is being changed. You must change the owner of any crontab files manually. You must change the owner of any at jobs
            manually. You must make any changes involving NIS on the NIS server.




            Try logging in with a different user and running the command again.



            If that isn't possible then you can manually edit the /etc/passwd file (which is actually what the usermod command is doing). If you do that make sure you back the file up in case you inadvertently do something silly.






            share|improve this answer














            The usermod command won't work if you're logged in with the user you are trying to make changes on.



            From the manual page on usermod it says:




            CAVEATS
            usermod will not allow you to change the name of a user who is logged in. You must make certain that the named user is not executing
            any processes when this command is being executed if the user's
            numerical
            user ID is being changed. You must change the owner of any crontab files manually. You must change the owner of any at jobs
            manually. You must make any changes involving NIS on the NIS server.




            Try logging in with a different user and running the command again.



            If that isn't possible then you can manually edit the /etc/passwd file (which is actually what the usermod command is doing). If you do that make sure you back the file up in case you inadvertently do something silly.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 9 at 12:04









            Jeff Schaller

            37.5k1052121




            37.5k1052121










            answered Feb 4 '16 at 8:47









            MattM

            7810




            7810




















                up vote
                4
                down vote













                You need to edit the /etc/passwd file to change home directory of users that are currently logged in.



                Edit the /etc/passwd with sudo vipw and change home directory of the user.



                vipw highly recommended other than vim or other editors since vipw will set lock to prevent any data corruption.






                share|improve this answer
























                  up vote
                  4
                  down vote













                  You need to edit the /etc/passwd file to change home directory of users that are currently logged in.



                  Edit the /etc/passwd with sudo vipw and change home directory of the user.



                  vipw highly recommended other than vim or other editors since vipw will set lock to prevent any data corruption.






                  share|improve this answer






















                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote









                    You need to edit the /etc/passwd file to change home directory of users that are currently logged in.



                    Edit the /etc/passwd with sudo vipw and change home directory of the user.



                    vipw highly recommended other than vim or other editors since vipw will set lock to prevent any data corruption.






                    share|improve this answer












                    You need to edit the /etc/passwd file to change home directory of users that are currently logged in.



                    Edit the /etc/passwd with sudo vipw and change home directory of the user.



                    vipw highly recommended other than vim or other editors since vipw will set lock to prevent any data corruption.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 4 '16 at 8:33









                    7171u

                    83548




                    83548




















                        up vote
                        0
                        down vote













                        A couple possible workarounds, depending on what you're hoping to solve:



                        Option 1. Add HOME=/var/www/html to your .bashrc



                        Option 2. Rename /home/myusername and then create a symlink to the desired directory.



                        mv /home/myusername /home/myusername-old
                        ln -s /var/www/html /home/myusername





                        share|improve this answer






















                        • bad habbit. after that, myusername-old can not be used by other user
                          – GeoMint
                          Jun 3 at 9:52














                        up vote
                        0
                        down vote













                        A couple possible workarounds, depending on what you're hoping to solve:



                        Option 1. Add HOME=/var/www/html to your .bashrc



                        Option 2. Rename /home/myusername and then create a symlink to the desired directory.



                        mv /home/myusername /home/myusername-old
                        ln -s /var/www/html /home/myusername





                        share|improve this answer






















                        • bad habbit. after that, myusername-old can not be used by other user
                          – GeoMint
                          Jun 3 at 9:52












                        up vote
                        0
                        down vote










                        up vote
                        0
                        down vote









                        A couple possible workarounds, depending on what you're hoping to solve:



                        Option 1. Add HOME=/var/www/html to your .bashrc



                        Option 2. Rename /home/myusername and then create a symlink to the desired directory.



                        mv /home/myusername /home/myusername-old
                        ln -s /var/www/html /home/myusername





                        share|improve this answer














                        A couple possible workarounds, depending on what you're hoping to solve:



                        Option 1. Add HOME=/var/www/html to your .bashrc



                        Option 2. Rename /home/myusername and then create a symlink to the desired directory.



                        mv /home/myusername /home/myusername-old
                        ln -s /var/www/html /home/myusername






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 9 '16 at 14:38









                        Archemar

                        19.5k93569




                        19.5k93569










                        answered Nov 9 '16 at 0:10









                        Dax Kerchner

                        1




                        1











                        • bad habbit. after that, myusername-old can not be used by other user
                          – GeoMint
                          Jun 3 at 9:52
















                        • bad habbit. after that, myusername-old can not be used by other user
                          – GeoMint
                          Jun 3 at 9:52















                        bad habbit. after that, myusername-old can not be used by other user
                        – GeoMint
                        Jun 3 at 9:52




                        bad habbit. after that, myusername-old can not be used by other user
                        – GeoMint
                        Jun 3 at 9:52










                        up vote
                        -1
                        down vote













                        You can only do this temporarily. This means that every time you login as that user you have to run this one command:



                        export HOME=/var/www/html


                        This way, you can make most applications think that your home directory is whatever location you use above.



                        ~ will also start to point to /var/www/html.



                        The applications this worked with for me were NPM and Maven.






                        share|improve this answer
























                          up vote
                          -1
                          down vote













                          You can only do this temporarily. This means that every time you login as that user you have to run this one command:



                          export HOME=/var/www/html


                          This way, you can make most applications think that your home directory is whatever location you use above.



                          ~ will also start to point to /var/www/html.



                          The applications this worked with for me were NPM and Maven.






                          share|improve this answer






















                            up vote
                            -1
                            down vote










                            up vote
                            -1
                            down vote









                            You can only do this temporarily. This means that every time you login as that user you have to run this one command:



                            export HOME=/var/www/html


                            This way, you can make most applications think that your home directory is whatever location you use above.



                            ~ will also start to point to /var/www/html.



                            The applications this worked with for me were NPM and Maven.






                            share|improve this answer












                            You can only do this temporarily. This means that every time you login as that user you have to run this one command:



                            export HOME=/var/www/html


                            This way, you can make most applications think that your home directory is whatever location you use above.



                            ~ will also start to point to /var/www/html.



                            The applications this worked with for me were NPM and Maven.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 11 at 11:54









                            Molten Ice

                            1265




                            1265



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


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




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f259791%2fhow-to-change-the-home-directory-of-the-currently-logged-in-user%23new-answer', 'question_page');

                                );

                                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






                                Popular posts from this blog

                                Peggy Mitchell

                                Palaiologos

                                The Forum (Inglewood, California)