You're basically asking: "How to copy settings and files from my user account to a new user account, skipping some settings?"
Migrating to a new user account
To move files from user old
to new
, you need to copy over the files and change the ownership accordingly:
sudo cp -r -d --preserve=mode,timestamps -T ~old ~new
sudo chown -R new: ~new
This should copy the files without modifying paths.
Now log in to a shell as new
. Either switch to a VTY using Ctrl + Alt + F1 and login as new
or login from a terminal using su new
. If you chose the first method, you can switch back with Ctrl + Alt + F7. From this point, it's assumed that you're logged in as new
.
If symbolic links exist which point to their old directories, find those links:
find ~ -lname '*/old/*' -ls
The file names of the symbolic links are printed, but no action has been taken. To create a new symlink ~new/path/to/symlink
pointing to ~old/point/to/target
, overwriting the old one, run:
ln -sf ~old/point/to/target ~new/path/to/symlink
There could be configuration files referring to the old ones, you can find those files with grep
:
grep -HrnI 'old' ~
If you get many results, consider being more specific, i.e. replace old
by /home/old
. Files will be listed with lines matching the search criteria, but no action is taken.
Debugging the old account
If you copy all settings and files, you're better off with removing the problematic files. For optimal results, it's a good idea to logout the subject user from a GUI session and log in a virtual console (switch to it using Ctrl + Alt + F1).
If you're suddenly being logged out, check ~/.xsession-errors
. You can do so by running:
less ~/.xsession-errors
Use arrow keys, Page Up/Down, Home or End to navigate, press Q to quit.
Sometimes the .gconfd/saved_state
file gets corrupt. You can remove this file with:
rm .gconfd/saved_state
After doing this, switch back to a GUI login by pressing Ctrl + Alt + F7. Log in and if the problem went away, you're done. Otherwise, log out and switch back to the virtual console using Ctrl + Alt + F1.
Another directory that can be emptied is ~/.cache
:
rm -r ~/.cache/*
Instead of loosing all files and settings, temporary move some folders. That can be done with:
mv folder{,-orig}
If a folder was not causing issues, remove the newly created folder and restore the old one:
rm -r folder
mv folder{-orig,}
Some folders that could cause problems (some may be nonexistent, in that case skip to the next folder):
.gnome
.gnome2
.kde
.config
.local
As with every modification, switch back to a GUI login and test it.
You can use recovery mode to add the standard user to the admin group (which is now called sudo in 12.04). Below is a set of simple instructions copied from my personal website.
Using Recovery Mode To Add Users To The Admin / Sudo Group
First shutdown your computer.
Then restart whilst holding shift
on the keyboard to load grub menu.
Select recovery mode
from the grub menu.
Select drop to root shell
from the recovery menu.
Use the following command to remount the drive mount -o rw,remount /
Now type adduser username sudo
replacing username with your user name ie. 'adduser phil sudo'
You should now see a message saying 'adding user' followed by 'done'.
Type shutdown -r now
to restart the computer.
EDIT: If it is telling you that user xxx does not exist, first you can use the following command to list users and make sure that you have the correct username
ls /home
The other option is add a new user, from recovery mode using the following commands :
useradd username -m -s /bin/bash
passwd username
adduser username sudo
Again replacing username
with your desired username.
Best Answer
This suggestion is based on a previous answer. It assumes you are using Ubuntu 12.04 LTS.
recovery mode
.root (Drop to root shell prompt)
and press enter.mount -o remount,rw /
REPLACE-WITH-USERNAME
to refer to it. Please replaceREPLACE-WITH-USERNAME
with your new username which is not working in the commands below.passwd REPLACE-WITH-USERNAME
groups REPLACE-WITH-USERNAME
nopasswdlogin
group, use the command below to remove it from this group.gpasswd --delete REPLACE-WITH-USERNAME nopasswdlogin
groups
command in step (7), use the command below to add it and make it the primary login group for this username.usermod -g REPLACE-WITH-USERNAME REPLACE-WITH-USERNAME
Note: Yes, the username is repeated twice. For example, if the username were
joeuser
the command would beusermod -g joeuser joeuser
,
)usermod -a -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare REPLACE-WITH-USERNAME
groups
command in step (7) to verify that the username was correctly added to the groups.reboot
sudo fdisk -l
to verify thatsudo
is working for you correctly.groups
command from step (7) to verify one last time that the username is a member of the groups it should be in. (Better safe than sorry, no?)