How to copy linux user from server to server.

  • Extract user, password, and group information from the 4 following files

    Find the user(s) you want to copy. Copy the entire line for each user.


    vi /etc/passwd

    Do the same for the shadow file.

    vi /etc/shadow

    Now on the group files. You will want to copy your user line, but you will also want to copy any lines that much any relevant groups.

    vi /etc/group
    vi /etc/gshadow

    Now if are using key authentication you will need to copy
    /home/user/.ssh/authorized_keys to the new server.

    First you will need to create the directories

    mkdir /home/user
    mkdir /home/user/.ssh

    Then copy authorized_keys file.

    ssh-copy-id [email protected]


    scp [email protected]:/home/user/.ssh/authorized_keys /home/user/.ssh/authorized_keys

  • I know a company I used to work for would push out files to severs to build the users on all of them across the company - I'm assuming it was something the four files you mention above.

    why not use a centralized login authority, like Active Directory? Of course not AD, since this is Linux (not that you can't)

  • @Dashrender Because you might want to have separate systems that all have the same set of user creds and certified keys for the sole purpose of IGNORING ALL BEST PRACTICE EVER.

  • I know you were just explaining how to do it but this is a simple task with Ansible.

    - name: Ensure user exists
        name: Joe
        state: present
        password: "password_hash"
        groups: wheel, libvirt

    Instead of needing the hash up front you can do things like:

    {{ Password1234 | password_hash('sha512') }}