Followers

Linux File Permissions

linux-file-permissions_featured-image
What we’ll cover in this article is how to identify permissions for files & directories and how to change them, as well as changing ownerships, groups, etc. Depending on what you want to do, you’ll want to make sure you have the appropriate permissions (obviously), so let’s find out how to change them.
Let’s start by making a file we can use.
I issued the “touch” command to make a file creatively named testfile.
Touch will just create an empty file but has all the same attributes as an actual file. You can see this by using “ls –l.”
Commands:
touch test file
mkdir workfolder
Linux File Permissions 1
The permisions are broken into 4 sections.
Linux File Permissions 2

chmod – adds and removes permissions

If you wanted to add or remove permissions to the user, use the command “chmod” with a “+” or “–“, along with the r (read), w (write), x (execute) attribute followed by the name of the directory or file.
chmod +rwx “name of the file”
chmod –rwx “name of the directory”
Linux File Permissions 3
chmod +x testfile – this would allow me to execute
chmod –wx testfile – this would take out write and executable permissions
You’ll notice that this only changes the permissions for the owner of the file, in this case roman.

Changing Permissions for the Group Owners & Others

The command is similar to what we did before, but this time you add a “g” for group or “o” for users.
chmod g+w testfile
chmod g-wx testfile
Linux File Permissions 4
chmod o+w testfile
chmod o-rwx workfolder
Linux File Permissions 5
Lastly you can change it for everyone: “u” for users, “g” for group, & “o” for others; uog or a (for all).
chmod ugo+rwx workfolder – will give read, write, execute to everyone
chmod a=r workfolder – will give only read perission for everyone

chgrp – changing groups of files & directories

Another useful option is to change file permission to the group owning the file. Perhaps you create the files, but people on the db2 team can write/execute as well. We use chgrp for this purpose.
Linux File Permissions 6
You can see above that testfile and the work folder belong to the users group.
Linux File Permissions 7
By issuing the command – chgrp “name of the group” “name of the file” – you can change this.
chgrp sales testfile
chgrp sales workfolder
This give sales control of the file & then I can take away permissions for everyone else.
Note: The group must exit before you try to assign groups to files and directories.

chown – changing ownership

Another helpful command is changing ownerships of files and directories. The command is “chwon” along with “name of new owner” & “name of file.”
Linux File Permissions 8
The files belonged to roman. To give ownership to tom, issue the command:
chown tom testfile
chown tom workfolder
We can also combine the group and ownership command by:
Linux File Permissions 9
chown -R tom:sales /home/roman/tsfiles
The above command gives tom the ownership of the directory tsfiles, and all files and subfolders. The -R stands for recursive which is why all sub folders and files belong to tom as well.
As opposed to: chown tom workfolder
This command will give ownership to tom but all sub files and directories still belong to the original owner. The -R will transfer ownership of all sub directories to the new owner.
As you can see, you have several options when it comes to permissions. You have the capability to dictate who can do what & the flexibility to limit usability among users. It may be easier to just give all permission to everyone but this may end up biting you in the end, so choose wisely.

Permission in numeric mode

The above way of changing permissions will work fine but you may also need to know how to change permissions in numeric mode. chmod is used in much the same way, but instead of r, w, or x you will use numbers instead.
What are the numbers?
0 = No Permission
1 = Execute
2 = Write
4 = Read
You basically add up the numbers depending on the level of permission you want to give.
Linux File Permissions 10
Examples:
chmod 777 workfolder
Will give read, write, and execute permissions for everyone.
Linux File Permissions 11
chmod 700 workfolder
Will give read, write, and execute permission for the user, but nothing to everyone else.
Linux File Permissions 12
chmod 327 workfolder
Will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for other users.
Permission numbers
0 = —
1 = –x
2 = -w-
3 = -wx
4 = r—
5 = r-x
6 = rw-
7 = rwx
Either variation of changing permissions will work, just remember how to use the numeric values.
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Adminsitrator
 

Linux Text Editors: Vi and Nano


linux-text-editors_featured-image
When working with text editors, you pretty much choose between Vi or Nano. Vi is old school with a blank layout and no visible controls, which can make it difficult to work with for beginners. However, it is very powerful and once you learn the keystrokes it can be used very quickly to edit config files and used for scripts, etc. Nano has a pseudo-graphical layout that makes it a little easier to jump right into. Both are viable options. Vi is a standard whereas Nano has to be available depending on the Linux OS you use. We will look at both and go over the important commands for both.
Let’s look at the difference.
To start Vi, you just have to type “vi” and then the name of the file, or type any name and the file will be created anew.
Example: “vi newfile”
Linux Text Editors 1
Vi will automatically open in Command mode. On the bottom you will see some info such as the name of the document & info on whether it is a new file or an existing one. Let’s look at an existing file.
Linux Text Editors 2
You will see additional info for existing files and more importantly whether you have to write premissions.

Quitting & Saving

There are three modes to Vi: Command mode, Text mode & Ex Mode. If you tried to start typing in command mode you wouldn’t be able to. You need to hit the “I” in order to get into text mode. You can then get back to command mode by the ESC key. Typng “:” will put you into Ex mode.
Linux Text Editors 3
In order to quit Vi, you have to hit the Esc key and then enter in “:” along with “q” for quit.
Linux Text Editors 4
If you get stuck in a file that is Read-Only and you can’t quit, you can enter “:q!” with the exlamation point to force quit. If you want to save changes, hit the Esc key along with “:w”.
Linux Text Editors 5
Linux Text Editors 6
In short, here are the keys for saving and quiting after hitting Esc (Ex mode):
  • :w – Saves
  • :wq or :x – Save & Quit
  • :q – Quit
  • :q! – Force quit, no save

Navigation in Vi

Navigating in Vi is a little more tricky, and this is what gives new users headaches. You just want to keep your fingers on your keyboard as if you are constantly typing (i.e. h, j, k, l). These keys are the substitute for the arrow keys.
  • j – down
  • k – up
  • l – right
  • h – left
  • gg – Takes you to the beginning of the file
  • G(shift + g) – Will take you to the end of the file
  • xxG – Brings you to a specific line in the file(xx is the line number)
  • ( – Move up to the beginning of the sentence
  • ) – Move to the end of the sentence

Insterting Text

  • i – Insert before cursor position
  • a – append after cursor position
  • r – Replace letter
  • o – Open line below cursor position automatically goes into insert mode
  • O – Open line above cursor in insert mode

Deleting Text

  • x – Deletes the character under cursor position
  • X – Deletes the character before cursor
  • dw – Deletes the word after cursor
  • db – Deletes word before the cursor
  • u – Will undo changes

Copy(yank) & Paste

  • yw – Yanks the word after the cursor
  • yb – Yanks the word before the cursor
  • yy – Yanks the entire line
  • p – Will paste
  • P – Will paste before the cursor position

Search

  • / – Is used to search(:/searchword)
Linux Text Editors 7
Linux Text Editors 8

Setting up Vi with numbers

It might benefit some to view the documents with numbers. What you want to do is go into Exec mode(ESC) and then type in “: set number”. Let’s look at the group file:
Linux Text Editors 9
Linux Text Editors 10

Nano

Let’s take a look at workinig with Nano. You start out the same way as you do with Vi by just typing “nano newfile”.
Linux Text Editors 11
The look is a lot different.
Published By
S.G.Godwin Dinesh.MCA
Sr.System Administrator

Set group password,its use and check which group after newgrp command in linux

As per the title of my post it has 3 questions:
(1) How to set group password in Linux ?
(2) What is its use ?
(3) How to know you are using which group after using command newgrp ?

How to set group password in Linux

Follow the given below steps to set group password
Step 1: Either you can create a new group or use the existence group.
To create new group use below command.

groupadd group_name
for eg.
groupadd hr
Step 2: To set group password use below given command
gpasswd group_name
For eg.
gpasswd hr

How to use group passwd

To use the permission and privileges of group you can temporarily join the group by using its group password
User can temporarily join the group which has password already set by below given command
newgrp group_name
for eg.

newgrp hr
In below given example we will see, the user called john do not have read,write,execute permission in directory called /opt/testdir.
The ls -ld command shows it has ownership of joe and group is hr and permission is 770 means only owner joe and group hr have read write execute permission.
But user john can also “read write execute” only when it uses the newgrp command and give group password of hr group.
See the below given scenario, how the john will create a testfile after using newgrp command which he was earlier not able to do so
root@tuxworld:~# ls -ld /opt/testdir/
drwxrwx--- 2 joe hr 4096 Jul 31 01:12 /opt/testdir/
root@tuxworld:~# 
root@tuxworld:~# su -l john
$ whoami
john
$ 
$ touch /opt/testdir/testfile
touch: cannot touch `/opt/testdir/testfile': Permission denied
$ 
$ newgrp hr
Password: 
$ 
$ touch /opt/testdir/testfile
$ ls -l /opt/testdir/testfile
-rw-rw-r-- 1 john hr 0 Jul 31 02:00 /opt/testdir/testfile
$ 
$ exit
$ exit
root@tuxworld:~# 
Note: You can use this in other scenario above one was just an example

How to know you are using which group after using command newgrp

$ groups
john
$ newgrp hr
Password: 
$ groups
hr john
$ id
uid=1011(john) gid=1012(hr) groups=1011(john),1012(hr)
$ groups
hr john
$ whoami
john
$ 
$ id john
uid=1011(john) gid=1011(john) groups=1011(john)
$ 
$ groups
hr john
$ exit
$ exit
To describe about this query I will first start with example.
(A)In below command user name is john and I use the command whoami. By which I got to know the username which I login is john
(B)After this I use the command id john which shows the user john’s UID and GId by which I can also know which is its primary or supplementary GROUPS.(i.e john ,john [here group is also john])
(C)Then I use the command called groups now here you can see the output in which it shows hr group which was not earlier listed with id command.
(D) Hence to know which group you are using after newgrp command ,check with below given two commands
1: id username
2: groups
(E)Now in next step you can see in example, I typed two times exit command .
The first exit command is when it exit out from group called hr
And the Second exit command is when I am doing exit from shell of user john
 
Published By
S.G.Godwin Dinesh.MCA
Sr.System Adminsitrator

Installing Software Using GPOs on Windows Server 2008

Imagine for a minute that your boss came in one day, gave you a Foxit DVD and said that everyone in your organization needs to get that DPF software that’s on this DVD installed today.
You think, well that’s great but are you sure you want all 500 people to get the software today?
That’s almost impossible, isn’t it? There isn’t enough time for you to walk around with the DVD and install it 500 times.
Sure there is! But you won’t be walking around with the DVD in your hand, that’s for sure.
The solution I’m going to show you today is quite simple, and much less time consuming
You are going to copy that software on a Shared Folder on your network. Then, you’re going to create a Group Policy Object, aka GPO, (aren’t you happy you installed Active Directory?) that will take that software and install it on everyone’s machines.
Easy, huh? Of course it is and it is not going to take you days, I promise.

What You Need Before Installing Software Using GPOs

There are 3 things you will need in order to have a successful Software Installation GPO:
1. The most important thing you will need is a Microsoft installer file, called .msi — you cannot use the .exe file that is on the DVD.
You will need to get a packaging utility to turn that .exe file into .msi file. Many of them are available for instant download from internet.
There are a few that will cost money but there are also free downloads. Here is an example from each:
2. The second thing you will need to create is a Shared Folder on your network for the software to live in. You need to make sure that every computer has at least “read” access to that folder and its contents.
3. And the last thing you will need is the new Group Policy Object linked to the appropriate Organization Unit.

How to Install Software Using GPOs

Assuming that you already have the .msi file ready, let’s start with creating a shared folder on our network.
1. Browse to the location on your network, right-click and select New, then Folder.
Installing Software Using GPOs on Windows Server 2008 - 1
2. Name the folder — in this example we are going to call it “Software”.
3. Select that folder and then click on the Share button on the menu toolbar.
Installing Software Using GPOs on Windows Server 2008 - 2
4. Like I mentioned above, every machine needs to have at least read access to this folder. To do this type in Everyone and hit enter, or click on the Add button.
Installing Software Using GPOs on Windows Server 2008 - 3
5. Make sure the Permission Level says Reader and then click the Share button.
Installing Software Using GPOs on Windows Server 2008 - 4
6. Remember or write down the location of this shared folder. In our example the location is \\NY-MEM1-2K8\Software
Installing Software Using GPOs on Windows Server 2008 - 5
7. Double click on the Shared Folder you just created and once again perform the steps to create a new folder.
This time name the folder with a name specific to the software you are about to install. We are going to call it “Foxit”.
Installing Software Using GPOs on Windows Server 2008 - 6
8. Double click on the new folder (“Foxit”) and copy and paste the .msi file for the software you want to install. Our .msi is called FoxitReader23.
Installing Software Using GPOs on Windows Server 2008 - 7
9. Now it is time to switch to your domain controller.
We are going to switch to our DC1 server. Once there, go ahead and open up Server Manager.
Installing Software Using GPOs on Windows Server 2008 - 8
10. Now you need to point to the Organizational Unit where the new Group Policy Object will reside.
To start off, go ahead and expand Features, then Group Policy Management, and then your Forest. In our example it is the Globomantics.com forest.
11. Then expand Domains and then the domain in which you want to create the GPO.
12. Once you are in the correct domain, expand the Organizational Unit. In our example, we are expanding NewYorkOU.
13. Since we want the software to be installed on every single computer, we are going to create the Group Policy Object in our NYComputers Organization Unit.
Go ahead and click on that OU.
Installing Software Using GPOs on Windows Server 2008 - 9
14. To create a new GPO, right-click on the appropriate Organization Unit and select Create a GPO in this domain, and Link it here…
Installing Software Using GPOs on Windows Server 2008 - 10
15. Name your new GPO and hit OK.
Installing Software Using GPOs on Windows Server 2008 - 11
16. To make sure the new GPO was created, go ahead and expand the Group Policy Objects.
You should see your GPO listed there. That GPO is now being linked to our NYComputers OU.
Installing Software Using GPOs on Windows Server 2008 - 12
17. Select and then right click on the GPO under the Organization Unit. Then select Edit.
Installing Software Using GPOs on Windows Server 2008 - 13
18. That should open a Group Policy Management Editor.
19. Go ahead and expand Computer Configuration, then Policies, and then Software Settings.
20. Next click on and select Software Installation.
Installing Software Using GPOs on Windows Server 2008 - 14
21. Right click on the right side of the Software Installation, select New and then click on Package.
Installing Software Using GPOs on Windows Server 2008 - 15
22. Browse to the location where your software .msi file exists.
In our example it is NY-MEM1-2K8 → Software → Foxit. Once you have located it, double click on the file or select it and then click on the Open button.
Installing Software Using GPOs on Windows Server 2008 - 16
23. Select Assigned and click OK.
Installing Software Using GPOs on Windows Server 2008 - 17

Testing

Before you actually go and test this on one of your client machines, do not forget to run a GPO Update. To do so, open up you command prompt on your Domain Controller and type in gpupdate /force.
Installing Software Using GPOs on Windows Server 2008 - 18
Installing Software Using GPOs on Windows Server 2008 - 19
Once the update ran through you can go to one of your clients and restart the machine. Keep in mind that in order for the software to be installed on a computer, you will need to do a hard reboot.


To send EMail from Other than SQL Agent Login in Database Mail

User attempting to send Database Mail does not have permission to execute sp_send_dbmail.


The error text is:
EXECUTE permission denied on object 'sp_send_dbmail', 
database 'msdb', schema 'dbo'.
To send Database mail, users must be a user in the msdb database and a member of the DatabaseMailUserRole database role in the msdb database. To add msdb users or groups to this role use SQL Server Management Studio or execute the following statement for the user or role that needs to send Database Mail.
So we can do it by following two methods.

(Or)
EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole'
,@membername = ''; GO
EXEC msdb.dbo.sp_addrolemember @rolename = 'DatabaseMailUserRole' ,@membername = 'TestDBmailUser'; GO

When a user has sent mail u can see message in your Mail box also we can see Mail status
Unsent/Failed Messages:
select mailitem_id,sent_status,recipients,subject,body,body_format from sysmail_allitems where sent_status not in ('Failed','unsent') order by mailitem_id desc
Sent Messages:
select mailitem_id,sent_status,recipients,subject,body,body_format from sysmail_allitems where sent_status in ('sent') order by mailitem_id desc

You can also see When Mail Queue Mode before and After kindly see below
Before Mail Send it was Inactive mode and After you has sent Mail it was changed to 
Receives_occuring mode.
Also u can see mail from your inbox

Scripts:
To Send Mail to Recipients:
DECLARE @p_body as nvarchar(max), @p_subject as nvarchar(max)
DECLARE @p_recipients as nvarchar(max), @p_profile_name as nvarchar(max)
SET @p_profile_name = 'Test Notify'
SET @p_recipients = N'ashok.kumar@gmail.com;ashok.kumar@yahoo.com'

SET @p_subject = 'Test for email'
SET @p_body = 'test' 
EXEC msdb.dbo.sp_send_dbmail
  @profile_name = @p_profile_name,
  @recipients = @p_recipients,
  @body = @p_body,
  @body_format = 'HTML',
  @subject = @p_subject
To Check Status of Email Messages for delivered or not:
select mailitem_id,sent_status,recipients,subject,body,body_format from sysmail_allitems where sent_status not in ('Failed','unsent') order by mailitem_id desc select mailitem_id,sent_status,recipients,subject,body,body_format from sysmail_allitems where sent_status in ('sent') order by mailitem_id desc
To Check Failditems:
SELECT sent_status,sent_date,items.last_mod_date,items.subject,items.last_mod_user,send_request_user,l.
description FROM dbo.sysmail_faileditems as items
INNER JOIN dbo.sysmail_event_log AS l
    ON items.mailitem_id = l.mailitem_id
order by last_mod_date desc

To Check Mail Queue:
sysmail_help_queue_sp @queue_type = 'Mail' ;
Published by
S.G.Godwin Dinesh.MCA
Sr.System Administrator