Showing posts with label CENTOS. Show all posts
Showing posts with label CENTOS. Show all posts

CentOS 5 "cannot find a valid baseurl for repo" Error Fix


When trying to update or install packages on older CentOS 5 systems, you may run into the following error.
root@server1 [~]# yum update -y
Loaded plugins: fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/
removing mirrorlist with no valid mirrors: /var/cache/yum/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
This is commonly caused by attempting to use deprecated repositories. The update repositories were moved to the CentOS vault when the operating reached it's end-of-life.

In order to continue using the operating system packages, you will need to update your repository entries to point to the vault.

Using your favorite text editor, open /etc/yum.repos.d/CentOS-Base.repo

Look for the following:
[base]name=CentOS-$releasever - Basemirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Comment out the mirror list, and uncomment the baseurl. So it should look like the following:
#mirrorlist=
baseurl=
Next, you will need to put in the URL for the vault repository.

for 32-bit systems, use: http://vault.centos.org/5.11/os/i386/

for 64-bit systems, use: http://vault.centos.org/5.11/os/x86_64/
For each repository, you will need to replace /os/ with what repository subdirectory you need. For example on a 64-bit system, for updates, your URL will look like http://vault.centos.org/5.11/updates/x86_64/ and for extras it will look like http://vault.centos.org/5.11/extras/x86_64/ Always check the old url first to make sure you have right path. You can also check http://vault.centos.org to see all available repositories.
Once you have added this, run the following to clean your yum cache:
yum clean all
Then update yum to start using the new repositories:
yum update

URL grabber error on yum update/install on CentOS7

URL grabber error on yum update/install on CentOS7

If you are using CentOS7, you may be already frustrated with the urlgrabber error while installing or updating the packages using yum.
[root@centos7 ~]# yum upgrade
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* epel: mirror.nus.edu.sg
* extras: centos.excellmedia.net
* updates: mirrors.vonline.vn
Traceback (most recent call last): 44% [=======================- ] 183 kB/s | 4.9 MB 00:00:33 ETA
File “/usr/libexec/urlgrabber-ext-down”, line 75, in <module>
main()
File “/usr/libexec/urlgrabber-ext-down”, line 61, in main
fo = PyCurlFileObject(opts.url, opts.filename, opts)
File “/usr/lib/python2.7/site-packages/urlgrabber/grabber.py”, line 1258, in __init__
self._do_open()
File “/usr/lib/python2.7/site-packages/urlgrabber/grabber.py”, line 1589, in _do_open
self._do_grab()
File “/usr/lib/python2.7/site-packages/urlgrabber/grabber.py”, line 1723, in _do_grab
self._do_perform()
File “/usr/lib/python2.7/site-packages/urlgrabber/grabber.py”, line 1517, in _do_perform
raise KeyboardInterrupt
KeyboardInterrupt
Exiting on user cancel

To fix this issue-

Edit the file /usr/lib/python2.7/site-packages/urlgrabber/grabber.py Change the line number 1510 as below Change “elif errcode in (42, 55, 56):” to “elif errcode == 42:"

Title : yum install exiting on user cancel | yum urlgrabber | file usr libexec urlgrabber ext down line 28 except oserror e | delta rpms disabled because /usr/bin/applydeltarpm not installed

How to Protect your Server Against the Shellshock Bash Vulnerability

Introduction

On September 24, 2014, a GNU Bash vulnerability, referred to as Shellshock or the "Bash Bug", was disclosed. In short, the vulnerability allows remote attackers to execute arbitrary code given certain conditions, by passing strings of code following environment variable assignments. Because of Bash's ubiquitous status amongst Linux, BSD, and Mac OS X distributions, many computers are vulnerable to Shellshock; all unpatched Bash versions between 1.14 through 4.3 (i.e. all releases until now) are at risk.
The Shellshock vulnerability can be exploited on systems that are running Services or applications that allow unauthorized remote users to assign Bash environment variables. Examples of exploitable systems include the following:
  • Apache HTTP Servers that use CGI scripts (via mod_cgi and mod_cgid) that are written in Bash or launch to Bash subshells
  • Certain DHCP clients
  • OpenSSH servers that use the ForceCommand capability
  • Various network-exposed services that use Bash
A detailed description of the bug can be found at CVE-2014-6271, CVE-2014-7169, CVE-2014-7186, and CVE-2014-7187.
Because the Shellshock vulnerability is very widespread--even more so than the OpenSSL Heartbleed bug--and particularly easy to exploit, it is highly recommended that affected systems are properly updated to fix or mitigate the vulnerability as soon as possible. We will show you how to test if your machines are vulnerable and, if they are, how to update Bash to remove the vulnerability.

Check System Vulnerability

On each of your systems that run Bash, you may check for Shellshock vulnerability by running the following command at the bash prompt:
env 'VAR=() { :;}; echo Bash is vulnerable!' 'FUNCTION()=() { :;}; echo Bash is vulnerable!' bash -c "echo Bash Test"
The highlighted echo Bash is vulnerable! portion of the command represents where a remote attacker could inject malicious code; arbitrary code following a function definition within an environment variable assignment. Therefore, if you see the following output, your version of Bash is vulnerable and should be updated:
Bash is vulnerable!
Bash Test
If your output does not include the simulated attacker's payload, i.e. "Bash is vulnerable" is not printed as output, you are protected against at least the first vulnerability (CVE-2014-6271), but you may be vulnerable to the other CVEs that were discovered later. If there are any bash warnings or errors in the output, you should update Bash to its latest version; this process is described in the next section.
If the only thing that is output from the test command is the following, your Bash is safe from Shellshock:
Bash Test

Test Remote Sites

If you simply want to test if websites or specific CGI scripts are vulnerable, use this link:'ShellShock' Bash Vulnerability CVE-2014-6271 Test Tool.
Simply enter the URL of the website or CGI script you want to test in the appropriate form and submit.

Fix Vulnerability: Update Bash

The easiest way to fix the vulnerability is to use your default package manager to update the version of Bash. The following subsections cover updating Bash on various Linux distributions, including Ubuntu, Debian, CentOS, Red Hat, and Fedora.

APT-GET: Ubuntu / Debian

For currently supported versions of Ubuntu or Debian, update Bash to the latest version available via apt-get:
sudo apt-get update && sudo apt-get install --only-upgrade bash
Now check your system vulnerability again by running the command in the previous section (Check System Vulnerability).

End of Life Ubuntu / Debian Releases

If you are running a release of Ubuntu / Debian that is considered end of life status, you will have to upgrade to a supported to use the package manager to update Bash. The following command can be used to upgrade to a new release (it is recommended that you back up your server and important data first, in case you run into any issues):
sudo do-release-upgrade
After the upgrade is complete, ensure that you update Bash.

YUM: CentOS / Red Hat / Fedora

Update Bash to the latest version available via yum:
sudo yum update bash
Now check your system vulnerability again by running the command in the previous section (Check System Vulnerability).

End of Life CentOS / Red Hat / Fedora Releases

If you are running a release of CentOS / Red Hat / Fedora that is considered end of lifestatus, you will have to upgrade to a supported to use the package manager to update Bash. The following command can be used to upgrade to a new release (it is recommended that you back up your server and important data first, in case you run into any issues):
sudo yum update
After the upgrade is complete, ensure that you update Bash.

Conclusion

Be sure to update all of your affected servers to the latest version of Bash! Also, be sure to keep your servers up to date with the latest security updates!
Source : https://www.digitalocean.com/community/tutorials/how-to-protect-your-server-against-the-shellshock-bash-vulnerability

How To Edit the Sudoers File on Ubuntu and CentOS

Introduction
Privilege separation is one of the fundamental security paradigms implemented in Linux and Unix-like operating systems. Regular users operate with limited privileges in order to reduce the scope of their influence to their own environment, and not the wider operating system.

A special user, called root, has "super-user" privileges. This is an administrative account without the restrictions that are present on normal users. Users can execute commands with "super-user" or "root" privileges in a number of different ways.

In this article, we will discuss how to correctly and securely obtain root privileges, with a special focus on editing the /etc/sudoers file.

We will be completing these steps on an Ubuntu 12.04 VPS, but most modern Linux distributions should operate in a similar manner.

This guide assumes that you have already completed the initial server setup discussed here. Log into your VPS as regular, non-root user.

How To Obtain Root Privileges
There are three basic ways to obtain root privileges, which vary in their level of sophistication.

Log In As Root
The simplest and most straight forward method of obtaining root privileges is simply to log into your VPS as root from the onset.

If you are using the "Console Access" button from the droplets page, simply enter "root" as the username and enter the root password when prompted.

 wemakeitsimple - sudo ssh server

If you are logging in through SSH, specify the root user prior to the IP address or host name in your connection parameters.

ssh root@your_IP_address_or_domain

Again, enter the root password when prompted.

Use "su" to Become Root
Logging in as root is usually not recommended, because it is easy to begin using the system for non-administrative tasks, which is dangerous.

The next way to gain super-user privileges allows you to become the root user at any time, as you need it.

We can do this by invoking the su command, which stands for "substitute user". To gain root privileges, simply type:

su

You will be prompted for the root user's password, after which, you will be dropped into a root shell session.

When you have finished the tasks which require root privileges, return to your normal shell by typing:

exit

Use "sudo" to Execute Commands as Root
The final, and most complex, way of obtaining root privileges that we will discuss is with the sudo command.

The sudo command allows you to execute one-off commands with root privileges, without the need to spawn a new shell. It is executed like this:

sudo command_to_execute

Unlike su, sudo will request the password of the user calling the command, not the root password.

Because of its security implications, sudo does not work by default, and must be set up before it functions correctly. If you followed the initial server setup guide, you already completed a bare-bones configuration.

In the following section, we will discuss how to modify the configuration in greater detail.

What is Visudo?
The sudo command is configured through a file located at /etc/sudoers.

Note: Never edit this file with a normal text editor! Always use the visudo command instead!
Because improper syntax in the sudoers file can leave you with a system where it is impossible to obtain elevated privileges, it is important to use the visudo command to edit the file.

The visudo command opens a text editor like normal, but then validates the syntax of the file upon saving. This prevents configuration errors from blocking "sudo" operations, which may be your only way of obtaining root privileges.

Traditionally, visudo opens the /etc/sudoers file with the "vi" text editor. Ubuntu, however, has configured visudo to use the "nano" text editor instead.

If you would like to change it back to "vi", issue the following command:

sudo update-alternatives --config editor

There are 3 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/nano            40        manual mode
  2            /usr/bin/vim.basic   30        manual mode
  3            /usr/bin/vim.tiny    10        manual mode


Select the number that corresponds with the choice you would like to make.

On CentOS, you can change this value by adding the following line to your ~/.bashrc:

export EDITOR=/path/to/editor

Source the file to implement the changes:

. ~/.bashrc

After you have configured visudo, execute the command to access the /etc/sudoers file:

sudo visudo

How To Modify the Sudoers File
You will be presented with the sudoers file in your selected text editor.

I have copied and pasted the file from Ubuntu 12.04, with comments removed (but including the addition we made in our initial server set up). The CentOS sudoers file has many more lines, some of which we will not discuss in this guide.

Defaults        env_reset
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

root        ALL=(ALL:ALL) ALL
demo        ALL=(ALL:ALL) ALL

%admin      ALL=(ALL) ALL
%sudo       ALL=(ALL:ALL) ALL


Let's take a look at what these lines do.

Default Lines
The first line, "Defaults env_reset", resets the terminal environment to remove any user variables. This is a safety measure used to clear potentially harmful environmental variables from the sudo session.

The second line, which begins with "Defaults secure_path=...", specifies the PATH (the places in the filesystem the operating system will look for applications) that will be used for sudo operations. This prevents using user paths which may be harmful.

User Privilege Lines
The third and fourth lines, we are somewhat familiar with. The fourth line you added yourself, but you might not have investigated the details of what each portion was accomplishing.

  • demo  ALL=(ALL:ALL) ALL
The first field indicates the username that the rule will apply to (demo).

  • demo     ALL=(ALL:ALL) ALL
The first "ALL" indicates that this rule applies to all hosts.

  • demo     ALL=(ALL:ALL) ALL
This "ALL" indicates that the demo user can run commands as all users.

  • demo     ALL=(ALL:ALL) ALL
This "ALL" indicates that the demo user can run commands as all groups.

  • demo     ALL=(ALL:ALL) ALL
The last "ALL" indicates these rules apply to all commands.

This means that our "root" and "demo" users can run any command using sudo, as long as they provide their password.

Group Privilege Lines
The last two lines are similar to the user privilege lines, but they specify sudo rules for groups.

Names beginning with a "%" indicate group names.

Here, we see the "admin" group can execute any command as any user on any host. Similarly, the "sudo" group can has the same privileges, but can execute as any group as well.

How To Set Up Custom Rules
Now that we have gotten familiar with the general syntax of the file, let's create some new rules.

How To Create Aliases
The sudoers file can be organized more easily by grouping things with various kinds of "aliases".

For instance, we can create three different groups of users, with overlapping membership:

User_Alias      GROUPONE = abby, brent, carl
User_Alias      GROUPTWO = brent, doris, eric,
User_Alias      GROUPTHREE = doris, felicia, grant


Group names must start with a capital letter. We can then allow members of GROUPTWO to update apt-get's database by creating a rule like this:

GROUPTWO    ALL = /usr/bin/apt-get update

If we do not specify a user/group to run as, as above, sudo defaults to the root user.

We can allow members of GROUPTHREE to shutdown and reboot the machine by creating a "command alias" and using that in a rule for GROUPTHREE:

Cmnd_Alias      POWER = /sbin/shutdown, /sbin/halt, /sbin/reboot, /sbin/restart
GROUPTHREE  ALL = POWER


We create a command alias called "POWER" that contains commands to power off and reboot the machine. We then allow the members of GROUPTHREE to execute these commands.

We can also create "Run as" aliases, which can replace the portion of the rule that specifies the user to execute the command as:

Runas_Alias     WEB = www-data, apache
GROUPONE    ALL = (WEB) ALL


This will allow anyone who is a member of GROUPONE to execute commands as the "www-data" user or the "apache" user.

Just keep in mind that later rules will override earlier rules when there is a conflict between the two.

How To Lock Down Rules
There are a number of ways that you can achieve more control over how sudo reacts to a call.

The updatedb command associated with the "mlocate" package is relatively harmless. If we want to allow users to execute it with root privileges without having to type a password, we can make a rule like this:

GROUPONE    ALL = NOPASSWD: /usr/bin/updatedb

NOPASSWD is a "tag" that means no password will be requested. It has a companion command called PASSWD, which is the default behavior. A tag is relevant for the rest of the rule unless overruled by its "twin" tag later down the line.

For instance, we can have a line like this:

GROUPTWO    ALL = NOPASSWD: /usr/bin/updatedb, PASSWD: /bin/kill

Another helpful tag is "NOEXEC", which can be used to prevent some dangerous behavior in certain programs.

For example, some programs, like "less", can spawn other commands by typing this from within their interface:

!command_to_run

This basically executes any command the user gives it with the same permissions that "less" is running under, which can be quite dangerous.

To restrict this, we could use a line like this:

username    ALL = NOEXEC: /usr/bin/less

Miscellaneous Information
There are a few more pieces of information that may be useful when dealing with sudo.

If you specified a user or group to "run as" in the configuration file, you can execute commands as those users by using the "-u" and "-g" flags, respectively:

sudo -u run_as_user command
sudo -g run_as_group command


For convenience, by default, sudo will save your authentication details for a certain amount of time in one terminal. This means you won't have to type your password in again until that timer runs out.

For security purposes, if you wish to clear this timer when you are done running administrative commands, you can run:

sudo -k

If you are simply wondering what kind of privileges are defined for your username, you can type:

sudo -l

This will list all of the rules in the /etc/sudoers file that apply to your user. This gives you a good idea of what you will or will not be allowed to do with sudo as any user.

There are many times when you will execute a command and it will fail because you forgot to precede it with "sudo". To avoid having to re-type the command, you can take advantage of a bash functionality that means "repeat last command":

sudo !!

The double exclamation point will repeat the last command. We preceded it with sudo to quickly change the unprivileged command to a privileged command.

For some fun, you can add the following line to your sudoers file with visudo:

sudo visudo

Defaults    insults

This will cause sudo to return a silly insult when a user types in an incorrect password for sudo. We'll use sudo -k to clear the previous sudo cached password to try it out:

sudo -k
sudo ls

[sudo] password for demo:    # enter an incorrect password here to see the results
Your mind just hasn't been the same since the electro-shock, has it?
[sudo] password for demo:
My mind is going. I can feel it.


ConclusionYou should now have a basic understanding of how to read and modify the sudoers file, and a grasp on the various methods that you can use to obtain root privileges.

Remember, super-user privileges are not given to regular users for a reason. It is essential that you understand what each command does that you execute with root privileges. Do not take the responsibility lightly. Learn the best way to use these tools for your use-case, and lock down any functionality that is not needed.

Tags : windows, linux, freebsd, mikrotik, server, networking