{"id":1875,"date":"2016-07-09T11:46:06","date_gmt":"2016-07-09T19:46:06","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1875"},"modified":"2016-07-09T11:46:06","modified_gmt":"2016-07-09T19:46:06","slug":"linux-clone-user","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2016\/07\/09\/linux-clone-user\/","title":{"rendered":"linux clone user"},"content":{"rendered":"<p>This worked on Linux Mint 18 Mate to clone a user. PlayOnLinux DragonNaturallySpeaking failed to change enough user info that it was nonfunctional, but two other PlayOnLinux applications did get moved successfully.<\/p>\n<p>======================<\/p>\n<p>create a script file, I called mine clone-user.sh, make it executable and add the following. When you run it run it as sudo.<\/p>\n<p><!--more--><\/p>\n<p>==start script==============<\/p>\n<pre>#!\/bin\/bash\n\n\n# clone a user\n# usage:\n# cd \/home\/tech\/scripts\n# sudo bash clone-user.sh\n\necho \"=============\"\necho \"this script will create a new user\"\necho \"based on an existing user's data\"\necho \necho \"You will be shown a list of users who can currently log on\"\necho \"Remember which user you would like to clone.\"\necho \"You will be asked for the new user's name, their password\"\necho \"and the old user to clone\".\necho \"=============\"\necho \n\necho -n \"New user's name: \"\nread newuser\necho -n \"New user's password: \"\nread newpassword\necho \necho \"Current users you can clone:\"\necho \"----\"\nawk -F'[\/:]' '{if ($3 &gt;= 1000 &amp;&amp; $3 != 65534) print $1}' \/etc\/passwd\necho \necho -n \"Old user to clone: \"\nread olduser\necho \necho \"You have selected: \"\necho \"----\"\necho \"new user: $newuser\"\necho \"new user password: $newpassword\"\necho \"old user: $olduser\"\necho \n\nolduser_GROUPS=$(id -Gn ${olduser} | sed \"s\/${olduser} \/\/g\" | sed \"s\/ ${olduser}\/\/g\" | sed \"s\/ \/,\/g\")\nolduser_SHELL=$(awk -F : -v name=${olduser} '(name == $1) { print $7 }' \/etc\/passwd)\n\necho \"old user groups: \"\necho \"----\"\necho $olduser_GROUPS\necho \"olduser shell: \"\necho $olduser_SHELL\n\nread -rsp $'Press any key to continue or ctrl-c to exit...\\n' -n1 key\n\nuseradd --groups $olduser_GROUPS --shell $olduser_SHELL $newuser\n\necho $newuser:$newpassword | chpasswd\n\nread -rsp $'ready to make home direcoty -- ctrl-c to exit...\\n' -n1 key\n\nmkdir \/home\/$newuser\nchown -R $newuser:$newuser \/home\/$newuser\n\necho \necho \"Script should be done now.\"\necho \necho \"Do you see your new users name below?\"\necho \nawk -F'[\/:]' '{if ($3 &gt;= 1000 &amp;&amp; $3 != 65534) print $1}' \/etc\/passwd\n\necho \necho \"We are now going to copy the old user's home folder to the new user\"\necho \"then change ownership to the new user\"\necho \nread -rsp $'Ready to copy home folder --- or ctrl-c to exit...\\n' -n1 key\n\nrsync -aPv \/home\/$olduser\/. \/home\/$newuser\/\nchown -R --from=$olduser $newuser:$newuser \/home\/$newuser\n\necho \necho \"Now we are going to change the names of files and folders to the new user\"\necho \n\ngrep -rlI $olduser \/home\/$newuser\/ . | sudo xargs sed -i 's\/$olduser\/$newuser\/g'\n\necho \necho \"Done now.\"\necho \nread -rsp $'Press any key to exit...\\n' -n1 key\necho \necho<\/pre>\n<p>==end script==============<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This worked on Linux Mint 18 Mate to clone a user. PlayOnLinux DragonNaturallySpeaking failed to change enough user info that it was nonfunctional, but two other PlayOnLinux applications did get moved successfully. ====================== create a script file, I called mine clone-user.sh, make it executable and add the following. When you run it run it as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1875","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1875"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1875\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}