Skip to main content

Posts

Unable to login to SSH even with a correct password

 In Linux world, SSH is a life. Especially, now with remote work, data center, servers without graphical interface. If you can't login via SSH,  even with a correct password but other user accounts is able to login. Then the person need to check with HR whether he or she is still on the payroll. :)  😄 Of course, glitch, errors and other issues will always be a part of this technology. Nothing is perfect in this world, so errors, technological issues will always be there it won't go away. So, what will will you do if you are sure that the SSH password and username is correct? Like you can login to Server 1, Server 2 but unable to login with Server 3 using the same credentials? If other users with sudo credentials are still able to login, the sudo account can be used to troubleshoot the specific SSH account that is having the issue. What would be the first thing to do? Well, joke as it seems that "restart works always" but the reality is not far from there. Restart SSH...

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

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, t...

PowerShell add text or string to text file without opening the file

How to add or append a string or any contents to a text file without opening the text file? Reading and writing in PowerShell is quite fundamental but very important. A simple PowerShell snippet code below, that will add or append a string to the text file dynamically. This is quite useful like monitoring a service, or pinging a server and adding the status or the result to a text file that can be checked later. Text file can be easily tampered, so proper permissions should be set who can write and read. So the file can be a source of truth, if ever auditing has to be done. Here's a simple PowerShell snippet that append a string to a text file or dynamically adding a string to a file. $contents_to_add=Get-Date Add-Content   -Path  "c:\temp\xx.rtf" -Value $contents_to_add #This will append a string to the existing content $file_content = get-content -Path  "c:\temp\xx.rtf" Write-Output $file_content  #Read the content of the files Just a short code but does a won...

Python Basics Read Text File and placed into variable

Python code below is a simple and basic code, that will open a text file in read only mode. Code below has been tested using Python3. It just demonstrates using a “print” statement to show the logic; how to open a file in read only mode and place the line that was read to a variable. The logic can be used on advance methods, such as replacing the line with IP Address and supplying a shutdown command to the IP Address. Here’s the code: #Open the file as Read Only with open('mysampledata.txt','r') as file_objHandler: #'mysampledata.txt' <--file name of the text file to be read #'r' <-- tell Python to open file as read only     #Read all lines in the file.     TxtLines = file_objHandler.readlines()     line_counter = 0   for Oneline in TxtLines:         #print(Oneline.strip())     line_counter += 1     print(line_counter, "<-- Line# / This is the data on...