Showing posts with label Linux Commands. Show all posts
Showing posts with label Linux Commands. Show all posts

Use HTTP PROXY via command line in Linux/FreeBSD

Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable

Linux / UNIX has environment variable called http_proxy. It allows you to connect text based session / application via the proxy server. All you need is proxy server IP and port values. This variable is almost used by all utilities such as elinks, lynx, wget, curl and others.

Assuming that your HTTP Proxy IP address is 192.168.0.1 port 3128 (standard proxy port)

Set http_proxy shell variable

Type the following command to set proxy server:

$ export http_proxy=http://server-ip:port/
$ export http_proxy=http://192.168.0.1.1:3128/
$ export http_proxy=http://proxy-server.mycorp.com:3128/

How do I setup proxy variable for all users?

To setup the proxy environment variable as a global variable, open /etc/profile file:
$ vi /etc/profile

In order to make this proxy permanent, add the line to your ~/.profile or /etc/profile or ~/(bash|ksh|sh)rc file.

Add the following information:
export http_proxy=http://proxy-server.mycorp.com:3128/

Save and close the file.

How do I use password protected proxy server?

$ export HTTP_PROXY='http://username:password@192.168.0.1:3128'

You can simply use wget as follows:

$ wget --proxy-user=USERNAME --proxy-password=PASSWORD http://path.to.domain.com/some.html

Lynx has following syntax:
$ lynx -pauth=USER:PASSWORD http://domain.com/path/html.file

Curl has following syntax:
$ curl --proxy-user user:password http://url.com/

To unset this, use:

$ export HTTP_PROXY=' '


Grub boot sequence change

Grub boot sequence change

To change boot sequence, just edit the configuration at /etc/grub.conf
("root" privilege is required)

I use vi as the text editor

vi /etc/grub.conf

On the parameters of default, change to the number of its partition on the hdd, like 0 in the example shown above. (hdd 0,0: Windows; hdd 0,1:swap; hdd 0,2:Fedora )

timeout is for the pending time for selection before it auto-boot the default choice, which is set to 5second on example above.

After changing to 0 (previously 2 for Fedora partition), pls kindly restart and it shall works!

reboot


Install Windows after Linux and dual-boot

With the new GRUB 2′s recent release, there has been a lot of messing around with GRUB Legacy which, to be honest, there's no need for. This tutorial will assume that you have Linux installed on your hard drive/virtual machine and just installed Windows to it but have lost your choice of booting Linux on startup. This is caused by Microsoft wanting their virus to pwn the rest and they overwrite the MBR only for their own operating systems. So we are going to re-install GRUB to the MBR.

There's only one requirement: You need a Live CD with which you can boot into.

Using your Live CD, boot into the Ubuntu pre-installed environment. Once in, make sure that your Linux partition is mounted. You can check this by copying the following and seeing the same or similar output to the command-line:

And take a note the designation for the disk /dev/sda which you will be using later, and the directory in /media. It may even be /dev/hda depending on your hard drive's framework. And also, the long directory with letters and numbers after /media/. This is the directory of the partition. In the example, I'll use my own but you may need to change yours accordingly.

ls /media/bdd1efeb-e61f-467a-968c-8cea0af9349b/boot

Now that you've got what you need mounted, run the following command to rewrite GRUB to your MBR:

sudo grub-install --root-directory=/media/bdd1efeb-e61f-467a-968c-8cea0

If this did not work and you get BIOS warnings, try:

sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b99

If for some reason the GRUB menu does not display Windows after your reboot, run into Ubuntu, open a terminal and run the following command:

sudo update-grub2

Now all you have to do is reboot making sure to boot to your hard drive and not to the live CD. GRUB should be installed and both Ubuntu and Windows should have been automatically detected and listed in the menu.

The Master Boot Record will execute GRUB as the initial bootloader. The Windows bootloader is contained within the Windows partition and will then be chainloaded by the GRUB bootloader.

It should work now.


Ownership and Permissions

One way to gain entry when you are denied permission is to su to root, as you learned earlier. This is because whoever knows the root password has complete access.

But switching to the superuser is not always convenient or recommended, since it is easy to make mistakes and alter important configuration files as the superuser.

All files and directories are "owned" by the person who created them. You created the file temp.txt in your login directory, so temp.txt belongs to you.

That means you can specify who is allowed to read the file, write to the file, or (if it is an application instead of a text file) who can execute the file.

Reading, writing, and executing are the three main settings in permissions. Since users are placed into a group when their accounts are created, you can also specify whether certain groups can read, write to, or execute a file.

Take a closer look at temp.txt with the ls command using the -l option

There is a lot of detail provided here. You can see who can read (r) and write to (w) the file, as well as who created the file (sams), and to which group the owner belongs (sams). Remember that, by default, the name of your group is the same as your login name.

Permissions for temp.txt

Other information to the right of the group includes file size, date and time of file creation, and file name.

The first column shows current permissions; it has ten slots. The first slot represents the type of file. The remaining nine slots are actually three sets of permissions for three different categories of users.

For example:

-rw-rw-r--

Those three sets are the owner of the file, the group in which the file belongs, and "others," meaning other users on the system.

-    (rw-)   (rw-)   (r--) 1 sams sams 
|      |       |       | 
type  owner  group   others
      

The first item, which specifies the file type, can show one of the following:

  • d - a directory

  • -(dash) - a regular file (rather than directory or link)

  • l - a symbolic link to another program or file elsewhere on the system

Beyond the first item, in each of the following three sets, you will see one of the following:

  • r - file can be read

  • w - file can be written to

  • x - file can be executed (if it is a program)

When you see a dash in owner, group, or others, it means that particular permission has not been granted. Look again at the first column of sneakers.txt and identify its permissions.

ls -l temp.txt
-rw-rw-r--    1 sam sam     150 Mar 19 08:08 sneakers.txt

The file's owner (in this case, sam) has permission to read and write to the file. The group, sam, has permission to read and write to sneakers.txt, as well. It is not a program, so neither the owner or the group has permission to execute it.

The chmod Command

Use the chmod command to change permissions. This example shows how to change the permissions on sneakers.txt with the chmod command.

The original file looks like this, with its initial permissions settings:

-rw-rw-r--    1 sam sam     150 Mar 19 08:08 temp.txt

If you are the owner of the file or are logged into the root account you can change any permissions for the owner, group, and others.

Right now, the owner and group can read and write to the file. Anyone outside of the group can only read the file (r--).

Caution

Remember that file permissions are a security feature. Whenever you allow anyone else to read, write to, and execute files, you are increasing the risk of files being tampered with, altered, or deleted. As a rule, you should only grant read and write permissions to those who truly need them.

In the following example, you want to allow everyone to write to the file, so they can read it, write notes in it, and save it. That means you will have to change the "others" section of the file permissions.

Take a look at the file first. At the shell prompt, type:

ls -l temp.txt

The previous command displays this file information:

-rw-rw-r--    1 sams sams     150 Mar 19 08:08 temp.txt

Now, type the following:

chmod o+w temp.txt

The o+w command tells the system you want to give others write permission to the file sneakers.txt. To check the results, list the file's details again. Now, the file looks like this:

-rw-rw-rw-    1 sams sams     150 Mar 19 08:08 temp.txt

Now, everyone can read and write to the file.

To remove read and write permissions from sneakers.txt use the chmod command to take away both the read and write permissions.

chmod go-rw temp.txt

By typing go-rw, you are telling the system to remove read and write permissions for the group and for others from the file sneakers.txt.

The result will look like this:

-rw-------    1 sams sams    150 Mar 19 08:08 temp.txt

Think of these settings as a kind of shorthand when you want to change permissions with chmod, because all you really have to do is remember a few symbols and letters with the chmod command.

Here is a list of what the shorthand represents:

Identities

u - the user who owns the file (that is, the owner)

g - the group to which the user belongs

o - others (not the owner or the owner's group)

a - everyone or all (u, g, and o)

Permissions

r - read access

w - write access

x - execute access

Actions

+ - adds the permission

- - removes the permission

= - makes it the only permission

Want to test your permissions skills? Remove all permissions from sneakers.txt - for everyone.

chmod a-rwx temp.txt

Now, see if you can read the file with the command cat sneakers.txt, which should return the following:

cat: temp.txt: Permission denied

Removing all permissions, including your own, successfully locked the file. But since the file belongs to you, you can always change its permissions back with the following command:

chmod u+rw temp.txt

Use the command cat sneakers.txt to verify that you, the file owner, can read the file again.

Here are some common examples of settings that can be used with chmod:

  • g+w - adds write access for the group

  • o-rwx - removes all permissions for others

  • u+x - allows the file owner to execute the file

  • a+rw - allows everyone to read and write to the file

  • ug+r - allows the owner and group to read the file

  • g=rx - allows only the group to read and execute (not write)

By adding the -R option, you can change permissions for entire directory trees.

Because you can not really "execute" a directory as you would an application, when you add or remove execute permission for a directory, you are really allowing (or denying) permission to search through that directory.

If you do not allow others to have execute permission to tigger, it will not matter who has read or write access. No one will be able to get into the directory unless they know the exact file name.

For example, type:

chmod a-x tiger

to remove everyone's execute permissions.

Here is what happens now when you try to cd to into tigger:

bash: tiger: Permission denied

Next, restore your own and your group's access:

chmod ug+x tiger

Now, if you check your work with ls -l you will see that only others will be denied access to the tigger directory.

Changing Permissions With Numbers

Remember the reference to the shorthand method of chmod? Here is another way to change permissions, although it may seem a little complex at first.

Go back to the original permissions for sneakers.txt:

-rw-rw-r--    1 sams sams     150 Mar 19 08:08 temp.txt

Each permission setting can be represented by a numerical value:

  • r = 4

  • w = 2

  • x = 1

  • - = 0

When these values are added together, the total is used to set specific permissions. For example, if you want read and write permissions, you would have a value of 6; 4 (read) + 2 (write) = 6.

For sneakers.txt, here are the numerical permissions settings:

 -  (rw-)   (rw-)  (r--)
      |       |      |
    4+2+0   4+2+0  4+0+0

The total for the user is six, the total for the group is six, and the total for others is four. The permissions setting is read as 664.

If you want to change sneakers.txt so those in your group will not have write access, but can still read the file, remove the access by subtracting two (2) from that set of numbers.

The numerical values, then, would become six, four, and four (644).

To implement these new settings, type:

chmod 644 temp.txt

Now verify the changes by listing the file. Type:

ls -l temp.txt

The output should be:

-rw-r--r--    1 sams sams     150 Mar 19 08:08 temp.txt

Now, neither the group nor others have write permission to sneakers.txt. To return the group's write access for the file, add the value of w (2) to the second set of permissions.

chmod 664 temp.txt
Warning

Setting permissions to 666 will allow everyone to read and write to a file or directory. Setting permissions to 777 allows everyone read, write, and execute permission. These permissions could allow tampering with sensitive files, so in general, it is not a good idea to use these settings.

Here is a list of some common settings, numerical values and their meanings:

  • -rw------- (600) - Only the owner has read and write permissions.

  • -rw-r--r-- (644) - Only the owner has read and write permissions; the group and others have read only.

  • -rwx------ (700) - Only the owner has read, write, and execute permissions.

  • -rwxr-xr-x (755) - The owner has read, write, and execute permissions; the group and others have only read and execute.

  • -rwx--x--x (711) - The owner has read, write, and execute permissions; the group and others have only execute.

  • -rw-rw-rw- (666) - Everyone can read and write to the file. (Be careful with these permissions.)

  • -rwxrwxrwx (777) - Everyone can read, write, and execute. (Again, this permissions setting can be hazardous.)

Here are some common settings for directories:

  • drwx------ (700) - Only the user can read, write in this directory.

  • drwxr-xr-x (755) - Everyone can read the directory; users and groups have read and execute permissions.

Technorati :
Del.icio.us :
Zooomr :
Flickr :


File Permissions and thchmod/chgrp/chown commands

1:58 AM by Yash Kalra 0 comments

A guide to setting up and changing file permissions in the Linux Operating Systerm.

The chmod/chgrp/chown commands are used to change the permissions/ownership
of files and/or directories. Linux is often used as a multi-user system and
it is not desirable that all users have access to all files and directories.

For eg. : On a multi-user environment in a corporate office using a central
server running linux , it might be required the accounts documents be shared
between employees of the acccounts department . At the same time, it might
be undesirable and indeed dangerous if anyone having access to the server
is able to read/edit them.

It is for such situations that Linux has a 3X3 permission system.

There are 3 levels of security for a file :

Read Permission : Permission to read a file (r)

Write Permission : Permission to edit a file (w)

Execute Permission : Permission to execute a file if it is executable
(x)

and 3 different levels for a directory :

Enter Permission : Permission to Enter into the Directory

Show Entry : Permission to see the contents of the Directory

Write Entry : Permission to make a new file or subdirectory in
the Directory

For granting the above permissions, users are divided into 3 different
sets

User : The owner of the file/directory - mostly the person
who created the file/directory

Group : Linux users can be divided in groups and one user can
be a member of more than one group.

A Group denotes all users who are members of group(s)
to which the owner of a file/directory belongs

Others : All users not in the group(s) of the owner.

For eg :

A user level r/w/x permission means only the owner can read, write and
execute the file

A group level r/w/x permission means only the members of group(s) to which
the owner belongs can read, write and execute the file

An other level r/w/x permission means Everyone can read/write/execute
the file.

The chmod Command

The chmod command is used to change the permissions of files/directories
in linux. It\\\'s syntax is as follows :

chmod -R/c/f/v [u / g / o / a] [+ / - / =] [rwxXstugo..]

for eg. if u want to give all users in the group of the owner just read
permission to a file called foo.txt, the command is

chmod g+r /home/aarjav/foo.txt

here g stands for group, + stands for giving permission (as against -
for taking permission away), r stands for read permission.

so g+r means ?give group read permission?. All users for the owners group
now have read permission to foo.txt

Now if they misbehave and u want to take their read permission away.
The command is the same as above, just substituting the + sign with a minus
sign

chmod g-r /home/aarjav/foo.txt

As shown the general format of the command is

chmod -R/c/f/v [u / g / o / a] [+ / - / =] [rwxXstugo]

here

u : user

g: group

o : others

a : all

+ : give permission

- : take permission away

= : cause the permissions given to be the only permissions of the file

r : read permission

w: write permission

x : execute permission

X: execute only if it is a directory or already has execute permission for
some user

s : set user or group ID on execution

t : save program text on swap device

u : the permissions that the user who owns the file has for it

g : the permissions that the owner?s group has for a file

o : the permissions that users not in the owner?s group have for it

(X, s, t, u, g and o are not required for common tasks)

the initial options -R/c/f/v are explained as follows :

-c : Displays names of only those files whose permissions are being changed

( --changes can also be used instead of -c )

-f : Suppresses display of error messages when a file?s permissions cannot
be changed

( --silent of --quiet can also be used instead of -f )

-R: Recursively changes the permission of all files in all subdirectories
of the directory whose

permissions are being changed

( --recursive can also be used )

-v : Displays results of all permission changes

( --verbose can also be used )


The
chown command

The chown command is used to change the user and/or group which owns one
or more files or directories. Its general format is :

chown [-Rcfv] [username][:.][groupname] foo.txt

The flags used above are same as those used in the chmod command . The
following are the different ways in which this command can be used :

  • The username followed by a dot or colon followed by a groupname changes
    both the user and group ownerships to those specified.
  • The username followed by a dot or colon and no groupname changes the
    user ownership as specified and changes the group ownership to the specified
    user?s login group.
  • If the colon or dot and groupname are specified without a username,
    then only the groupownership is changed. This is effectively the same as
    the chgrp command.

  • If the username is not followed by a dot or a colon, then only the
    user ownership is changed.

The chgrp command

The chgrp command is used to change the group ownership of one or more files
or directories. Its general syntax is :

chgrp [-Rcfv] groupname foo.txt

The flags used here are also the same as those in the chmod command. The
changes in ownership are applied to the groupname and the filename specified.


Technorati :
Del.icio.us :
Zooomr :
Flickr :