ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to copy linux user from server to server.

    IT Discussion
    copy user linux ubuntu
    4
    4
    251
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • I
      IRJ
      last edited by IRJ

      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.

      example:
      user:x:1001:1001::/home/user:/bin/bash

      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 myuser@remoteserver
      

      or

      scp myuser@remoteserver:/home/user/.ssh/authorized_keys /home/user/.ssh/authorized_keys
      
      1 Reply Last reply Reply Quote 4
      • D
        Dashrender
        last edited by

        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)

        D 1 Reply Last reply Reply Quote 0
        • D
          DustinB3403 @Dashrender
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • S
            stacksofplates
            last edited by stacksofplates

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

            - name: Ensure user exists
              user:
                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') }}
            
            1 Reply Last reply Reply Quote 3
            • 1 / 1
            • First post
              Last post