Change file owner

What i did:

  • logged in with acc1 and created a new user acc2
    commands used: useradd and passwd.
  • Then i logged in acc2. but all the files are owned by acc1.

Issue: I try to change the owner of the files using chown command . But it gives me a error message.

All i want to do is create a file in one of these folder?
Am i using the correct method??:wall:

Thanks

Where are the file the second id wants access to, and what acces does it need?

Root can chown files to anyone. You can make both same group and make group readable or even writable.

It is not wise to have mixed ownership in a subtree - only root can remove all id files and dirs unless permissions are wide open.

When i login from my id 'Ubuntu' and create a user 'johns' . The user is created.
Now when johns logins using login command, and runs 'ls -l' command, he will see that all files are owned by 'Ubuntu' and the group is Ubuntu.

If the file permission on this file needs to be changed to 777 (read, write, execute to all) How do i do it. ?

Can i change the ownership of it?? I tried
chown Johns filename
but no use?

Log in as Ubuntu and try "chown -R johns ~johns".

777 is wide open, a+rwx for command chmod

What is johns group (run 'id')?

Commands i ran:

sudo useradd johns
sudo passwd johns 
... i entered the password twice ......
sudo login johns
--- enter johns password....
whoami           ---- returns johns
 ls -l                 ----- returns  drwxr-xr-x 2 ubuntu ubuntu  80 2011-08-01 17:05 Desktop

I want to create a file in Desktop but when i enter :

echo "please help" > MyDoc
-su: cannot create MyDoc: Permission denied

OR

sudo chown johns Documents
[sudo] password for johns: 
johns is not in the sudoers file.  This incident will be reported.

Maybe sudo does not do a right useradd, as most users get a login home directory they own!

Why sudo to login as johns?

After login, are you in a johns-specific home dir?

If yes, run id to find johns' group, and use sudo to "chown -R johns <home_dir>" and "chgrp -R <group_name> <home_dir>", and you should be fine.

If no, I recommend making one, not opening up permissions to all. At most, put them in the same group and open up group permissions.

Why sudo to login as johns?
When i do useradd, it does not allow me to create the user.

After login, are you in a johns-specific home dir?
PN: when the user is created it login home directory is the root
I dont understand how to go to Johns directory. Please guide me

If yes, run id to find johns' group, and use sudo to "chown -R johns <home_dir>" and "chgrp -R <group_name> <home_dir>", and you should be fine.

If no, I recommend making one, not opening up permissions to all. At most, put them in the same group and open up group permissions.
how do i make them in the same group

Sorry for asking dumb questions , I am kinda new to this

Generally, root and admin ids use root as home, not application users. User and app files should not clutter root, they should be in dedicated sub-directories. Some users like to try to run flat with almost no directories, but that is not good practice. Usually, each user gets a /home/<user_name>/ home dir.

Groups can be created with groupadd, and users can be attached at creation time or later, but if the critical group is not the original, default group, the user may need to newgrp to change groups. If you have a user and files/dirs you want to share, their group you want on this id is on these files/dirs. If they are still inaccessible with matching groups, and you want this, "chmod -R g+rw <top_dir>" will ensure all have group read write on the whole sub-tree.

When I login to the terminal and run the command whoami i get ubuntu
pwd command returns /home/ubuntu

Am I the administrator. [I am doing this on my computer for learning. ]?
I need to create another user. Do i change my settings and become the admin?

Even when you login as johns ? The home dir is defined in /etc/passwd unless they moved it. Perhaps use sudo to make johns a home dir, set the ownership, group and modes, and then change the johns login home dir. I expect root is the admin superuser, still, and ubuntu is the default first user. You don't want to run around crushing things accidentally as superuser. sudo takes you to root

in /etc/passwd there is a line
johns:x:1000:1000::/home/johns:bin/sh

But when i try to go cd /home/johns I get 'No such file or directory'

Perhaps use sudo to make johns a home dir, set the ownership, group and modes, and then change the johns login home dir. ? How do i do this?

sudo mkdir /home/johns
sudo chown johns /home/johns
sudo chgrp <diff_group> /home/johns # if_diff_group
sudo chmod 755 /home/johns

Usually, the final, login shell field starts with a / (absolute path): johns:x:1000:1000::/home/johns:/bin/sh

I created the folder johns and made john the owner of it.
But when i try to login, I get the message 'johns is not in the sudoers file. This incident will be reported'

Also when i try to change the group , it says says <diff_group> is not valid

If you have a different group, you need to run that line with the different group. <diff_group> is a meta-string for your replacement.

Maybe you need to hit the man pages to add johns to the sudoers file, if you want thate login to have that much power, or go back to bare login, or even bare su.