8

I want to export all my accounts login/password from Keychain. But you have many categories like : login, iCloud, System... in the Keychain menu. In fact I want to export them to 1Password, so I follow this overflow answer.

But in ~/Library/Keychains/ I have only the login.keychain and not the hopefully iCloud.keychain...

I have 422 accounts in the iCloud category and only 5 on the login category...

So my question is, how can I save/export this iCloud category

enter image description here

into a keychain or .csv file ?

EDIT :

I have already a login.keychain file. But I don't know how I can make an iCloud.keychain file.

enter image description here

StrawHara
  • 4,893

4 Answers4

7

A late reply, as I found this post while searching for something related.

You have to create a new keychain, and copy your iCloud keychain items to the new local keychain. Then you can use the security tool to dump them.

Since this is 1Password-related question, for others in the future, you can use MrC's conversion utility to directly convert the keychain dump into a 1Password consumable 1PIF file. It is much better than CSV importing.

https://discussions.agilebits.com/discussion/30286/mrcs-convert-to-1password-utility/p1

MrC
  • 86
  • seems to be the fastest way — create a new keychain, then copy the keys into it, then close the keychain. Move it to the new mac, then open with Keychain Access (or double click on the file), then copy the keys into the master keychain. Works beautifully. – lucasart Dec 18 '19 at 08:14
  • 2
    as of Catalina, there seems to be no way to copy iCloud keychain items. Attempting to copy them in the Keychain app results in an ambiguous error message. And the CLI security tool doesn't show awareness of the iCloud keychain at all. – Chris Apr 28 '20 at 08:45
  • @Chris The said applescript works on Safari 12. With some changes, it can work on Safari 13 also https://apple.stackexchange.com/questions/359377/mojave-icloud-keychain-copy-paste-error/409708#409708 – anki Dec 24 '20 at 20:37
  • Within the Keychain Access app using Ventura, the 'ambiguous error message' appears to be: "An error has occurred. Unable to add an item to the current keychain: One or more parameters passed to a function were invalid." – Glenn 'devalias' Grant Apr 28 '23 at 05:16
3

It's easy. Open Safari, go to Preferences, and then Passwords. Click on the three dots at the bottom, you will see Import Passwords and Export Passwords. This will export as .csv. Also, the passwords are not masked or Encrypted.

agarza
  • 2,274
Ash
  • 31
2

I'm on 10.13.6. The MrC's tool, while great for the local keychain, it didn't work for me for iCloud items. Nor did the script to retrieve passwords from Safari.

moxiefrog at 1Password forums posted a solution based on Automator that worked for me. Essentially, this script mimics a user doing copy-paste from each item to a text file.

Below is moxiefrog's code which I have adapted for my macOS version. You may have to adjust the number of tabs (see keystroke tab below), also taking into consideration what fields you would like to copy. As it is, running the script will produce a text file with the following format:

username,website,password

Steps

  1. Open TextEdit and create a new document
  2. Open Keychain
  3. Click on the iCloud keychain and sort it in the order that will be copied to the text document
  4. Locate the line keystroke "password" and insert your password (including the quotes)
  5. Run it once and check if it copied successfully, otherwise you may have to adjust the delay's and/or order and number of tabs.
  6. If everything went fine, increase the repeat value in the first line. Doing batches of 50 is recommended.
  7. Save the text file file as .csv.

Script

repeat 1 times
    delay 0.2
    tell application "Keychain Access"
        activate
    tell application "System Events"
        --- Open a keychain item
        delay 0.2
        keystroke return
        --- Press Tab x3
        delay 0.1
        keystroke tab
        delay 0.1
        keystroke tab
        delay 0.1
        keystroke tab

        -- Press ⌘C to copy item title
        delay 0.2
        keystroke "c" using command down
    end tell
end tell

--Switch to TextEdit
delay 0.2
tell application "TextEdit"
    activate
    tell application "System Events"
        -- Press ⌘V
        delay 0.2
        keystroke "v" using command down

        -- Type a comma
        delay 0.2
        keystroke ","

    end tell
end tell

--Switch to Keychain
tell application "Keychain Access"
    activate
    tell application "System Events"
        -- Press Tab x2 
        delay 0.1
        keystroke tab

        -- Press ⌘C
        delay 0.2
        keystroke "c" using command down
    end tell
end tell

--Switch to TextEdit
delay 0.2
tell application "TextEdit"
    activate
    tell application "System Events"
        -- Press ⌘V
        delay 0.2
        keystroke "v" using command down

        -- Type ','
        delay 0.2
        keystroke ","
    end tell
end tell

--Switch to Keychain
tell application "Keychain Access"
    activate
    tell application "System Events"
        -- Click the “Show password:” checkbox.
        delay 0.2
        keystroke "c" using {shift down, command down}

        -- Type password - update to yours
        delay 0.5
        keystroke "password"
        delay 0.2
        keystroke return

        -- Close keychain item window
        delay 0.3
        keystroke "w" using command down

        -- Go to next keychain item
        delay 0.2
        key code 125
    end tell
end tell

--Switch to TextEdit
delay 0.2
tell application "TextEdit"
    activate
    tell application "System Events"
        -- Press ⌘V
        delay 0.2
        keystroke "v" using command down

        -- Press Return
        delay 0.2
        keystroke return
    end tell
end tell

end repeat end run

Disclaimer

Use at your own risk. If you know how to use AppleScript and Automator, then you might be just dangerous enough to screw things up. Good Luck!

iled
  • 151
0

1Password 4 for Mac now supports importing of CSV format files

iCloud (Apple) Keychain items can be exported to a CSV file using script: Convert OS X Keychain exported entries into logins for 1Password import

Another option is to save new items to 1Password after they've been filled with login details from Safari's AutoFill (which can remain enabled as long as you'd like).

please refer this discussions. You'll probably find particularly helpful posts #20 from AgileBits and #39 from AgileBits.

nelson
  • 2,356
  • 13
  • 17
  • This github script take the login.keychain but I want the iCloud category. So my question is, how can I export the iCloud category into .keychain file for using the git script above or how can I export the iCloud category directly in CSV. – StrawHara Jan 22 '15 at 11:40
  • (If you have multiple keychains you should repeat this whole process once from step 2 onwards for each one. You will have to change 'login.keychain' to 'foo.keychain' or somesuch.) – nelson Jan 22 '15 at 11:56
  • So, that's why I am asking for "how to make the iCloud.keychain" file... You can see my edit above. – StrawHara Jan 23 '15 at 09:54