pipeline {
    agent any

    stages {
        stage('User Create') {
            steps {
                sh 'echo "User Create"'
                sh '''
                    ssh -i /var/lib/jenkins/.ssh/aws-iot3 -o StrictHostKeyChecking=no ubuntu@10.10.10.10 << "ENDSSH"
                    
                    sudo groupadd new_user

                    sudo useradd -g new_user -m new_user

                    sudo mkdir /home/new_user/.ssh
                    
                    sudo cp /home/ubuntu/.ssh/authorized_keys /home/new_user/.ssh 
                    
                    sudo chown -R new_user:new_user /home/new_user/.ssh
                    
                    sudo systemctl restart ssh
 
                    sudo su -
                    
                    sudo usermod -aG sudo new_user

                    sudo chmod 640 /etc/sudoers
                    
                    sudo echo 'new_user ALL=(ALL:ALL) ALL' | sudo cat >> /etc/sudoers 
                    

                    sudo cp /etc/sudoers.d/90-cloud-init-users /etc/sudoers.d/90-mysudoer
                    
                    sudo chmod 640 /etc/sudoers.d/90-mysudoer
                    
                    sudo echo 'new_user ALL=(ALL) NOPASSWD:ALL' | sudo cat >> /etc/sudoers.d/90-mysudoer
                      
                    sudo chmod 440 /etc/sudoers.d/90-mysudoer
                    

                    sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
                    
ENDSSH
                '''
            }
        }
    }
}

 

 

+ Recent posts