23

I have an Acer Aspire ZG5 netbook which is currently running Jolicloud, but I've decided it isn't for me and plan to switch to Lubuntu or Xubuntu.

However, I do lot of travelling and have many saved wifi passwords for different offices, hotels, cafes, restaurants, friends' and relatives' houses etc. It would be very annoying to have to ask for and reenter all of these passwords.

Is there a way to transfer my saved wifi passwords from the old installation to the new one?

con-f-use
  • 18,813
Adam
  • 331

6 Answers6

13

On my 12.04 system the WiFi connections and passwords (in the clear) were stored in text files in /etc/NetworkManager/system-connections/

Stopping the network manager, copying these files to the new machine, restoring the permissions and restarting network manager worked for me.

sudo stop network-manager
sudo cp /backup/path/etc/NetworkManager/system-connections/* /etc/NetworkManager/system-connections/
sudo chown root.root /etc/NetworkManager/system-connections/*
sudo start network-manager
Tom Brown
  • 131
  • 1
  • 3
  • 1
    Does not work on 14.04 – Marc Dec 07 '15 at 15:56
  • Works perfect also on Ubuntu 16.04 to 16.10. I copied the files from 16.04 and restored the passwords in 16.10, they appear in the Network Manager after a session restart (did not try the stop/start network-manager, could also work). Don't have the wifi networks to actually see if they connect automatically, but as they appear over there, they should also connect. – conualfy Nov 02 '16 at 23:19
  • Works also to stop/start the network-manager service if you use: sudo /etc/init.d/network-manager start (or stop) – conualfy Nov 02 '16 at 23:45
  • start/stop use initctl to communicate with Upstart init daemon. Use the systemd way: sudo systemctl stop NetworkManager.service. – Pablo Bianchi Oct 05 '17 at 14:00
  • 1
    Works in Ubuntu 19.10 (replace the first and fourth command mentioned above as follows:

    sudo /etc/init.d/network-manager stop sudo /etc/init.d/network-manager start

    – Ajith Natarajan Feb 11 '20 at 19:44
  • Still works great in 20.04, wifi network immediately connected after restarting network manager, although I use sudo service network-manager stop and then later with start; good to know there's so many ways to control system services... – SpinUp __ A Davis Feb 23 '21 at 14:12
11

On Ubuntu 16.04, copying the files from /etc/NetworkManager/system-connections/ was not enough. The files contain the wlan interface MAC address, and I also had to correct that to make it work.

The following procedure worked for me to import the wireless configs from my old 12.04 system to the new 16.04 installation.

# Stop Network Manager
sudo /etc/init.d/network-manager stop

copy the files from your old system (adapt as needed)

sudo rsync -va -c "/media/$YOUR_OLD_SYSTEM/etc/NetworkManager/system-connections/" /etc/NetworkManager/system-connections/

Get your new MAC address, and verify it is right.

For example, this should work if you have only one wireless interface

export MAC=$(iw dev | grep addr | awk '{print $2}') echo "$MAC"

Replace the MAC address in all the system-connections files

sudo perl -i.bak -pe 's/^(mac-address=)(.)/$1$ENV{MAC}/' /etc/NetworkManager/system-connections/

Restart NetworkManager, and wait for nm-applet to also start and connect

sudo /etc/init.d/network-manager start

Delete the backup files with the old MAC addresses

sudo rm /etc/NetworkManager/system-connections/*.bak

If for some reason you would like to keep the original timestamps of your system-connections files instead of the timestamp when you changed the MAC address, here is an alternative which assumes that you have 2 separate folders with your old and current connection files:

old=/etc/NetworkManager/system-connections.old
new=/etc/NetworkManager/system-connections
for f in $old/*; do b="$(basename "$f")"; perl -pe 's/^(mac-address=)(.*)/$1$ENV{MAC}/' "$f" > "$new/$b"; touch -r "$f" "$new/$b"; done
Pablo Bianchi
  • 15,657
mivk
  • 5,312
  • You can combine grep with awk with iw dev | awk '/addr/ {print $2}'. Maybe more modern would be to use systemctl stop network-manager.service. – Pablo Bianchi Oct 19 '20 at 02:10
  • For my migration from Ubuntu 22.04 to Ubuntu 22.04 on another machine, I had to do the same thing with interface-name instead of mac-address. – hife Jan 13 '24 at 11:21
3

Your passwords are stored in ~/.gnome2/keyrings. By default, they are protected with your login password. If you copy that folder to your new system and use the same login password, then you should have all of your passwords, including your wifi connections.

Your Passwords

You can see your passwords in the Passwords and Encryption Keys application. They should be under a keyring called login. You can search for "Network secret" to show only wifi passwords.

mv ~/.gnome2/keyrings ~/old_keyrings
cp ~/backup/keyrings ~/.gnome2/keyrings

However, for network manager to use your password, it needs a gconf setting with a matching id number. You can do this two ways: copy your old gconf settings or create new connections and change their id numbers.

Copy your old gconf settings

This is really simple:

# network-manager will overwrite your changes if you don't terminate it
sudo stop network-manager
# back up old settings
mv ~/.gconf/system/networking/connections ~/old_connections
cp /media/old_install/.gconf/system/networking/connections  ~/.gconf/system/networking/connections
sudo start network-manager

Unfortunately, this method didn't work for me. My test case is abnormal, so hopefully it works for you.

Create new connections

If the above doesn't work for you, then on your old machine:

  1. open Passwords and Encryption Keys
  2. right click on your default keychain
  3. select change password
  4. set the password to blank
  5. copy the ~/.gnome2/keyrings/default.keyring to ~/old_passwords.keyring
  6. Now you can connect to networks and look up passwords in ~/old_passwords.keyring (since you removed the password, it will be a plain-text file).

(You could also create connections and modify their uuid to match the existing password, but that's too much work unless you can script it.)

idbrii
  • 3,162
1

Extending the solution from Pablo Bianchi on Ubuntu 20.04, I simply had to remove the MAC-adress after copying:

cd /etc/NetworkManager/system-connections
service NetworkManager stop
sed -i -e 's/mac-address=.*$/mac-address=/' -- *
service NetworkManager start
zx485
  • 2,426
1
  1. Shut down NetworkManager

    sudo /etc/init.d/network-manager stop
    pkill nm-applet
    
  2. Copy ${HOME}/.gconf/system/networking/connections/
  3. Restart network-manager:

    sudo /etc/init.d/network-manager start
    

    Press Alt+F2 and enter nm-applet --sm-disable to start the applet.

Might be a litte out of date.

con-f-use
  • 18,813
  • Aren't the gconf settings only necessary if you have specific settings for different networks (you used network manager to edit your connection to change MTU, DHPC settings, etc...). All my passwords are stored in my keyring. – idbrii Jun 01 '11 at 14:00
  • Last time I checked, both was necessary. – con-f-use Jun 01 '11 at 14:03
  • Yes, you're right. network-manager doesn't bother to look in the keychain unless there's a matching uuid in the gconf settings. – idbrii Jun 01 '11 at 15:17
1

JoliCloud is based on 10.04, so I'd assume that it is using Network Manager to organize wireless passwords. Much of that configuration is stored in .gconf/system/networking/ -- Not sure if the passwords are stored there or elsewhere.

Amanda
  • 9,333