Wednesday, December 30, 2015

managing local linux users and groups

display command output to terminal ignore all errors:::   2>/dev/null
send command output to files ;errors to different file::   >file 2>file2
send output and errors to the same new,empty files::: &>file
send output and errors to the same file but preserve existing file content::: >>file 2>&1
run a command but throw away all possible terminal displays:: &>/dev/null
send command output to both the screen and a file at the same time::; |tee file
run command save output in a file discard error messages ::: >file 2>/dev/null



managinf local linux users and groups:::

 id command gives the information about the current logged in user
 ps = to see the processes on the current shell
 ps -a to see all the processes
 example of some use of sudo is given below:::
 [ashok@new-host-4 ~]$ tail /var/log/secure
tail: cannot open â/var/log/secureâ for reading: Permission denied
[ashok@new-host-4 ~]$ sudo tail -n3 et

[sudo] password for ashok:
Sorry, try again.
[sudo] password for ashok:
tail: cannot open âetâ for reading: No such file or directory
[ashok@new-host-4 ~]$ logout
bash: logout: not login shell: use `exit'
[ashok@new-host-4 ~]$ exit
exit
[kamal@new-host-4 root]$ su ashok
Password:
[ashok@new-host-4 root]$ su
Password:
[root@new-host-4 ~]# su ashok
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ cat: /var/log/secure: Permission denied
bash: cat:: command not found...
Similar command is: 'cat'
[ashok@new-host-4 ~]$ [ashok@new-host-4 root]$ cd
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ [ashok@new-host-4 ~]$ sudo tail /var.log.secure
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ tail: cannot open â/var.log.secureâ for reading: No such file or directory
bash: tail:: command not found...
Similar command is: 'tail'
[ashok@new-host-4 ~]$ [ashok@new-host-4 ~]$ sudo tail /var/log/secure
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ Dec 30 13:15:45 new-host-4 gdm-launch-environment]: pam_unix(gdm-launch-environm                                                                             ent:session): session opened for user gdm by (uid=0)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:16:09 new-host-4 polkitd[763]: Registered Authentication Agent for uni                                                                             x-session:c1 (system bus name :1.30 [gnome-shell --mode=gdm], object path /org/f                                                                             reedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:16:47 new-host-4 sshd[2968]: Accepted password for ashok from 192.168.                                                                             1.7 port 49493 ssh2
bash: Dec: command not found...
[ashok@new-host-4 ~]$ Dec 30 13:16:48 new-host-4 sshd[2968]: pam_unix(sshd:session): session opened fo                                                                             r user ashok by (uid=0)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:17:34 new-host-4 su: pam_unix(su-l:session): session opened for user r                                                                             oot by ashok(uid=1000)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:17:39 new-host-4 su: pam_unix(su:session): session opened for user kam                                                                             al by ashok(uid=0)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:17:49 new-host-4 su: pam_unix(su:session): session opened for user ash                                                                             ok by ashok(uid=1002)
bash: syntax error near unexpected token `('
[ashok@new-host-4 ~]$ Dec 30 13:20:58 new-host-4 sudo:   ashok : TTY=pts/0 ; PWD=/root ; USER=root ; C                                                                             OMMAND=/sbin/usermod ashok
bash: Dec: command not found...
bash: C: command not found...
[ashok@new-host-4 root]$ Dec 30 13:22:02 new-host-4 sudo:   ashok : TTY=pts/0 ; PWD=/home/ashok ; USER=ro                                                                             ot ; COMMAND=/bin/tail /var.log.secure
bash: Dec: command not found...
bash: ot: command not found...
bash: /var.log.secure: No such file or directory
[ashok@new-host-4 ~]$ Dec 30 13:22:34 new-host-4 sudo:   ashok : TTY=pts/0 ; PWD=/home/ashok ; USER=ro                                                                             ot ; COMMAND=/bin/tail /var/log/secure
bash: Dec: command not found...
bash: ot: command not found...
bash: /var/log/secure: Permission denied
[ashok@new-host-4 ~]$ [ashok@new-host-4 ~]$ tail /var/log/secure
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ tail: cannot open â/var/log/secureâ for reading: Permission denied
bash: tail:: command not found...
Similar command is: 'tail'
[ashok@new-host-4 ~]$ [ashok@new-host-4 ~]$ sudo tail -n3 et
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$
[ashok@new-host-4 ~]$ [sudo] password for ashok:
bash: [sudo]: command not found...
[ashok@new-host-4 ~]$ Sorry, try again.
bash: Sorry,: command not found...
[ashok@new-host-4 ~]$ [sudo] password for ashok:
bash: [sudo]: command not found...
[ashok@new-host-4 ~]$ tail: cannot open âetâ for reading: No such file or directory
bash: tail:: command not found...
Similar command is: 'tail'
[ashok@new-host-4 ~]$ [ashok@new-host-4 ~]$ logout
bash: [ashok@new-host-4: command not found...
[ashok@new-host-4 ~]$ bash: logout: not login shell: use `exit'
> [ashok@new-host-4 ~]$ exit
> exit
> [kamal@new-host-4 root]$ su ashok
> Password:
> [ashok@new-host-4 root]$ su
> Password:
> [root@new-host-4 ~]# su ashok

> here is another example of excessig file using sudo that could be only accessed by root user...
[ashok@new-host-4 ~]$ sudo vi etc/motd
groupadd helps to add group::: syntax   groupadd -r ashok adds automatically the group id number from the valid one

[sudo] password for ashok: we need to have our user password not the root one..
after that the file opens and we can make our own edit according to our choice using insert mode.

 usermod::
 userdel::
 useradd::

 [root@new-host-4 ~]# id sachin
uid=1003(sachin) gid=1003(sachin) groups=1003(sachin)
[root@new-host-4 ~]# id ramesh
uid=1004(ramesh) gid=1004(ramesh) groups=1004(ramesh)
[root@new-host-4 ~]# userdel ramesh
[root@new-host-4 ~]# useradd hari
[root@new-host-4 ~]# id hari
uid=1004(hari) gid=1004(hari) groups=1004(hari)

a newly assigned user always takes the id that is recently available which may be the id of recently deleted one.so if we just delete the user not its home directory with options -r , the new user can get access to that content..

No comments:

Post a Comment