Can’t connect to WPA/WPA2 Enterprise Wifi Network in Ubuntu

Sometimes you may find that you are in some Enterprise Wifi network and you can connect in Windows but not in Ubuntu without CA server certificate.

The following workarounds can help solve the problems:

Open /etc/NetworkManager/system-connections/<WifiName>  file with super-user permissions. <WifiName> is the name of Wifi Network( If name if “Corp Wifi”, the file name should be “Corp\ Wifi”) If no such file exist than you have not connected to Wifi yet. Try connecting to Wifi once.

If any prompt comes asking for CA Server Certificate, select Ignore.

Open /etc/NetworkManager/system-connections/<WifiName> file and remove the following line

system-ca-cert=true

I found this solution on stackoverflow where this solution was reportedly not working on 14.04.

For 14.04 instead of removing complete line,
Change the line to

system-ca-cert=false

The second solution for 14.04 worked for me. If any of the solution is not working then please comment below.

Advertisements

resolvconf not modifying resolv.conf

In some Linux distributions, and other Unix-like operating systems, the resolvconf program maintains the system information about the currently available name servers and manages the contents of the configuration file resolv.conf, which determines Domain Name System (DNS) resolver parameters.

When computer connects to the internet, the domain name must be convert to corresponding IP address. The Domain Name Server is responsible for this conversion by maintaining a list of domain names and corresponding IP address. The information about the servers is kept in the configuration file resolv.conf.

The resolv.conf file exist at location /etc/resolv.conf which is a symbolic link to /run/resolvconf/resolv.conf. When computer connects to internet, resolvconf gets the name-servers from DHCP and list in resolv.conf file. But sometimes this fails to happen.

One of the reason may be that you deliberately change /etc/resolv.conf file to fill name-servers manually. Now /etc/resolv.conf file is no more a symbolic link and resolvconf doesn’t update /etc/resolv.conf file. Now you find yourself in all problems related to resolv.conf.

The solution is to configure resolvconf again. Make a backup copy of resolv.conf and use the following command

sudo dpkg-reconfigure resolvconf

Answer Yes to all queries which follow.

Increasing speed of Tor

Follow the given procedure to speed up the tor.

  1. Backup the torrc file, save as torrc.bak.
  2. Append the following lines in the torrc file.

# Try for at most NUM seconds when building circuits. If the circuit isn't
# open in that time, give up on it. (Default: 1 minute.)
CircuitBuildTimeout 5
# Send a padding cell every N seconds to keep firewalls from closing our
# connections while Tor is not in use.
KeepalivePeriod 60
# Force Tor to consider whether to build a new circuit every NUM seconds.
NewCircuitPeriod 15
# How many entry guards should we keep at a time?
NumEntryGuards 8

Restoring default groups in Ubuntu

Sometimes it happen that user messes up with the groups of its user account while trying adding or removing some group or doing something which indirectly affect them. Ubuntu provides following command to add user to the group:
usermod -G group1,group2,... user
The default action of the command is that the user is added to the specified groups but removed from all other groups. -a parameter is needed to be given to append the group instead of replacing.
It is one of the most common lapse from user and they ended up with their sudoer account not able access many of the resources.

The solution to this is to find out the default groups and then adding them explicitly. One can ask someone who has unmodified groups the list of groups his account is added to.
groups gives the list of groups to which the current user is added.

Instead the user can also view the default groups without needing others help. There exists a log file which is created at the time of installation containing the log of processes it has gone through. The addition of user to different groups is definitely one of the process. The path of file is /var/log/installer/syslog.
Just view the log output which contain user-setup as a substring.
cat /var/log/installer/syslog | grep user-setup

The output comes as
Jun 29 22:35:54 ubuntu user-setup: pwconv: failed to change the mode of /etc/passwd- to 0600
Jun 29 22:35:54 ubuntu user-setup: Shadow passwords are now on.
Jun 29 22:35:55 ubuntu user-setup: Adding user `userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Adding new group `userabc' (1000) ...
Jun 29 22:35:55 ubuntu user-setup: Adding new user `userabc' (1000) with group `userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Creating home directory `/home/userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Copying files from `/etc/skel' ...
Jun 29 22:35:57 ubuntu user-setup: addgroup: The group `lpadmin' already exists as a system group. Exiting.
Jun 29 22:35:57 ubuntu user-setup: Adding group `sambashare' (GID 124) ...
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `adm' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group adm
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `cdrom' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group cdrom
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `dip' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group dip
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `lpadmin' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group lpadmin
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `plugdev' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group plugdev
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `sambashare' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group sambashare
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: adduser: The group `debian-tor' does not exist.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `sudo' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group sudo
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:37:45 ubuntu ubiquity: Removing user-setup ...
Jun 29 22:37:45 ubuntu ubiquity: Purging configuration files for user-setup ...

  • The lines containing ‘Adding user userabc to group xyz’ gives the groups in which user was added which are its default groups. Manually add the user to these groups and don’t forget -a parameter.
    Login to root account.
    usermod -a -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare userabc
  • You need to logout and again login to view the change.
  • Give command groups to view the groups. The newly added default groups should be there.

Configuring Proxy Authentication Settings in Linux

Configuring the proxy settings in a system is fairly simple task and easy interface is provided in every Operating system to do so. However, few linux distros are devoid of proxy authentication settings which should be there in every proxy settings interface. The browsers and other applications which require internet access provide their own configuration box to get the  settings from the user. But the frustration occurs when system ends up showing something like ‘Proxy Authentication error’, while using apt-get or installing application from software manager or doing some other task where system require net access..

Here are the steps to set proxy authentication in debian based distros:

  1. Edit /etc/apt/apt.conf file using superuser permissions. If not there, create new.

    sudo gedit /etc/apt/apt.conf

  2. Add or edit the content to be in following format

    Acquire::http::proxy "http://username:password@proxy_server:proxy_port/”;
    Acquire::https::proxy "https://username:password@proxy_server:proxy_port/”;
    Acquire::ftp::proxy "ftp://username:password@proxy_server:proxy_port/";
    Acquire::socks::proxy "socks://username:password@proxy_server:proxy_port/";

Git commands that I use most frequently

Following are the git commands that I have required many times. So I have compiled them here.

  • Adding remote repository and doing an initial push

git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master

For the bitbucket repository, fourth command can be changed as

git remote add origin https://username@bitbucket.org/username/repo.git

  • Removing a file from remote repository which has been deleted from local repository

git commit -a -m "Message"

-a flag will delete the files which have been deleted on local repository.

  • Undo git add a file if git commit is not done

git reset HEAD filepath

Interview Questions on linked-lists, doubly linked-lists and binary trees

I have collected few very good problems on linked-lists surfing through the internet. They include basic conceptual questions as well as hard to bite. I will keep update the blog as soon as I find some good stuff.

  1. Given a linked list, give an algorithm to reverse it using constant space and in single pass.
  2. Given a linked list of n nodes, give an algorithm to reverse every k nodes of the linked list.
  3. A linked list has a closed loop in it, i.e. the last node points to some node in middle of it. Give an algorithm to find the node from which the loop begins. The last node may points to the first node
  4. Given a linked list with each node having a lower-case character. Find whether the word formed by characters of list is palindrome or not.(Do in a single pass with constant space)
  5. Given a doubly linked-list containing integers in sorted sequence, create a height balanced binary search tree model using the same data structure.

Extended Euclidean Algorithm to find Modular Multiplicative Inverse

Modular multiplicative inverse of a number a mod m is a number x such that

ax ≡ 1 (mod m)

It is very helpful where division is carried out along with modular operation. Instead of dividing by a number, its inverse can be multiplied to fetch the same result i.e.

k/a mod m = k*x mod m

Modular multiplicative inverse can be find only if the two numbers are coprimes i.e. their gcd is 1.
Here we are using Extended Euclidean Algorithm to find the inverse.

The algorithm is same as Euclidean algorithm to find gcd of two numbers. Euclid’s algorithm starts with the given two integers and forms a new pair that consists of the smaller number and the remainder of the division of larger number with smaller number numbers. The new pair again applied given algorithm until the remainder is zero. The only extension in extended euclidean algorithm is that every divisor and remainder is represented as linear combination of the original two numbers and coefficients are stored in every iteration.

Algorithm:

We have to find x such that ax ≡ 1 (mod m)
Above equivalence can be stated alternatively as:
ax  = pm + 1
or ax + my = 1 known as Bézout’s identity.

The beginning two numbers are a and m
x and y are coefficients of a and m respectively when dividend is represented as linear combination of a and m.
u and v are coefficients of a and m respectively when divisor is represented as linear combination of a and m.
c and d are coefficients of a and m respectively when remainder is represented as linear combination of a and m.

Initially dividend is m and divisor is a
m = 0*a + 1*m = x*a + y*m
a = 1*a + 0*m = u*a + v*m
So x = 0, y = 1, u = 1, v = 0

m = q*a + r where q is quotient and r is remainder.
From next iteration q  acts as dividend and r as divisor. Let e is dividend and f is divisor in iteration.

e = q*f + r
r = (-q)*f + 1*e = (-q)*(u*a + v*m) + 1*(x*a + y*m) = (x – u*q)*a + (y – v*q)*m

So
c = x – u*q
d = y – v*q
For next iteration roles will be switched as:
f is dividend ⇒ e = f
r is divisor ⇒ f = r
x = u
y = v
u = c
v = d

Termination:

When r is 1
r = c*a + d*m = 1
c is the required modular inverse.

Example:

Consider example of two numbers  a = 29, m = 168

29x + 168y = 1
168 = 0*29  + 1*168                          
29   = 1*29 + 0*168                         

First Step:
168 = 5*29 + 23    
23 = (-5)*29 + 1*168 = (-5)*[1*29 + 0*168] + 1*[0*29  + 1*168]

Second Step:
29 = 1*23 + 6
6 = 1*29 + (-1) *23 = 1*[0*168 + 1*29] + (-1)*[(-5)*29 + 1*168] = 6*29 + (-1)*168

Third Step:
23 = 3*6 + 5
5 = 1*23 + (-3)*6 = 1*[ (-5)*29 + 1*168] + (-3)*[6*29 + (-1)*168] = (-23)*29 + 4*168

Fourth Step:
6 = 1*5 + 1
1 = (-1)*5 + 1*6 = (-1)*[(-23)*29 + 4*168] + 1*[6*29 + (-1)*168] = 29*29 + (-5)*168

Hence final solution comes as:
29*29 + (-5)*168 = 1
x = 29 and y = (-5)

C/C++ Implementation:


int modmulinverse(int a,int m)
{
    int x = 0,y = 1,u = 1,v = 0; 
    int e = m,f = a;
    int c,d,q,r;
    while(f != 1)
    {
        q = e/f;
        r = e%f;
        c = x-q*u;
        d = y-q*v;
        x = u;
        y = v;
        u = c;
        v = d;
        e = f;
        f = r;
    } 
    u = (u+m)%m;
    return u;
}