Skip to main content

Posts

Showing posts from October, 2022

Create an admin account on Azure VM to reset forgotten password

How to create an administrator account on Azure VM? On Azure environment, username and password of the authorized account is needed in order to login or connect via Remote Desktop. If the administrator password or the password to RDP has been forgotten, then logging in to the VM will be an issue. How to resolve this kind of issue? PowerShell is a friend for this kind of dilemma. Code snippet below will create a user account, and set the created account as a member of the administrator group. # Create a user account   $username = "azure_admin_22" $password = ConvertTo-SecureString "Dynamic_Admin_User_2022" -AsPlainText -Force New-LocalUser -Name "$username" -Password $password -FullName "$username" -Description "User Description"   # Add the user to "Administrators" groups Add-LocalGroupMember -Group "Administrators" -Member azure_admin_22 User account that will be created is: azure_admin_22 with the pass

Basic Ansible copy file/files to remote server

Copying files to remote server is needed at times, like deploying a new certificate or just some readme notes or other files that are just necessary in order to complete a task. Working with a single server, is not an issue. However, managing or deploying a file to a multiple servers could be daunting by doing it manually from server to server. Ansible is a good tool to copy files in one go, to multiple servers. Below is a sample code that would copy a file or group of files to specified servers. This can be a run as ansible adhoc playbook on an ansible node controller. {{ item }} <-- is the place holder for all file or files to be copied with_items <-- are the variables that will be placed on {{ item }} and it will be copied to the specified destination         with_items:           - test.crt           - server.crt           - filetest.pem #==========Ansible code below ---      - name: Copy file or files to remote servers or host     #multiple servers, use: server_1:server_2:se

How to uncomment a conf file in Linux via ansible

How to uncomment or enable a setting in a config file in Linux using Ansible? Ansible is quite a good tool,  as it helps to make a lot of changes on a few servers with a minimal effort. Of course, the challenge is you need to know what you want. And also create an Ansible yaml file that will accomplish the task. Example YAML file for Ansible below is able to make some changes on the Linux logrotate.conf file. On Linux logrotate.conf, it has some text like the string below. Note this is just an example and you can tweak it to other settings as desired. # uncomment this if you want your log files compressed #compress The logrotate.conf file, the compress setting is commented. To enable the setting the # or the comment key must be removed. How to remove the comment in order to enable the setting? Well, if there's only a single server do it the simple way. Login to the server and edit the file using vim or nano or other text editor. However, if there are quite a few servers. Ansible

Linux SSH using Python and run remote commands

 SSH in Linux using Python and run commands on remote server A simple code snippet in Python to SSH to a remote system on a Linux Enviroment and run some commands Simple code snippet below, to get the serial number host on a remote system and save the output to the local host where the Python was executed. Python code snippet below is just a two-liner, that will SSH to a remote system and execute some commands and save the output locally. Save the output as "ssh_get_serial.py" or any filename as desired, and run as python3 ssh_get_serial.py. import subprocess  subprocess.Popen("ssh {user}@{host} {cmd}".format(user='root', host='server.web01.internal', cmd='s dmidecode -t system | egrep "Serial|Product";hostname > /tmp/server-sn-check.txt '), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() import subprocess <-- module to be imported in Python subprocess.Popen("ssh {user}@{host} {cmd}" {user}

How to burn iso to CD or DVD in using Windows command line

Burning ISO is quite common especially if you need a bootable disc to install a software to a laptop, desktop or a server. So, how to burn an ISO image in Windows without a 3rd party software? The answer is yes it is possible. In a Window 10 or Windows 11, laptop or device a USB DVD/CD burner is needed. Of course, a blank DVD or CD is needed as well. How to burn an ISO image in a Windows command line? Open a windows command prompt, press Windows Key + R this will open run box and type "cmd" and press enter. Or simply, search for CMD on Windows menu and click on it. On Windows command prompt type: cd c:\windows\syswow64 on a 64 bit architecture machine. on c:\windows\syswow64 type the full path where the ISO can be found. Example: c:\windows\syswow64\isoburn  VMware-VMvisor-Installer-7.0U3g-20328353.x86_64.iso  So, the syntax is: isoburn path-to-the-iso-file  the burner will be automatically detected by the CLI. Sample image below of the ISOBurn. Once the ISO burn opens, tick