04_Byobu sessions

In the last articles I have shown you how you can work with windows and panes to create multiple working environments.
However setting these up every time you connect to a server would be quite annoying.

This is where byobu sessions come into play.

You can detach from a running session by using Ctrl + a ---> d .

If there is only one session present you can reconnect to it by running byobu.

On the one hand this means that this way you get back into your session when you connect to a device using ssh.
Just keep on working where you left off. Also you dont disconnect from lets say an IRC.

On the other hand however this also means that multiple people can connect to a session.
In this example I connect from a windows host over ssh using putty to a VM on that I have a byobu session open.
Both terminals are updated in realtime.

This is very handy when you want to teach multiple people.
All the users ssh into test machines and when something is unclear you can connect to that users session and discuss the question on a beamer.

Cheers,
Ori


Why microsoft (teams)?

Create a chatclient in 2018...

On mouseover Pop-Ups are blocking the text you want to copy?
[x] Check

Eating up over 400MB Ram when idle?
[x] Check

But I bet it has a giant scrollbackbuffer...
[x] Not really check

But the wonderful Giphy GIFS !!
... different search results for private and groupchats...


... and you cannot see how to find a gif someone else used, when you want to use it yourself.
(At least you can copy and paste it...)

 

Nuff said,
Ori

 


03_Byobus split personality

One of byobus most useful features is to split the shell.
This is where the name and logo come from, a Byōbu is a Japanese folding screen.

If you split the shell vertically using Ctrl + a ---> % the similarity gets quite obvious.

Those splitt off areas in your window are called "Pane" (singular) or "Panes" (plural).
The new right hand shell gets started as a separate shell.

Even if I changed into the context of root before sending the split shell command the shell will be started as a normal user.
This is because the initial byobu session has not been started as root.

With a split command you always split the pane that you are in currently.
UsingCtrl + c ---> | you can split the current pane horizontally.

You can switch from one pane to another using Ctrl + a ---> Arrowkey
The direction of the arrow defines where you jump to.

If you use the arrow keys in a fast manner you can jump multiple panes.
In this example I first press Ctrl + a and then in a fast motion Arrow Up, Arrow Left.

If you start a command in a pane it keeps running, even if you switch into another one.
I will start htop in this example, switch into the upper pane to check the disk usage with watch df -h.
(Watch repeats a command every 2 seconds and df -h means disk free human readable)

Then I update the sources and run an upgrade using
apt update && apt upgrade -y

Also you can resize the pane that you are in right now using Shift + Arrow Keys.

Using these techniques you can customize multiple windows with multiple panes in all of them suited to fit your needs.
One for Network and Firewall settings, one in wich you are working with docker, one for scripting etc...

Cheers,
Ori


Generating an SSH keypair in windows

Windows does not come with out of the box tools (that I am aware of) to create an ssh keypair.

You can install the Linux Subsystem für Windows.
There you can create a keypair using ssh-keygen.

Alternatively you can install PuTTY that comes with PuTTYgen.
In the lower half of PuTTYgen you can define the Keytype and length and then click on generate.

Some flopping the mouse around later you can export your public and private key.

Cheers,
Ori


02_Byobu Commands

You should early on get used to using commands instead of F1 - F12.
A byobu command begins with Ctrl+a followed by a character.

If you press ctrl+a for the first time you will be asked wether you want to work in the screen or emacs mode.

This setting defines what escape sequence you want to use.
I use screen, so Ctrl+a.
If you use the Emacs setting it will be Ctrl+b to send a command and Strg+a jumps to the beginning of a line (as it usually would).

Once you made that choice you can start using Ctrl+a (or Ctrl+b) to send commands.
To do this press Ctrl+a, then release all key and then press the command key.

A new window for example gets created using Ctrl+a ---> c

You might be thinking that this is way more complicated then just pressing F2 and you might be right about that.
However, once you want to send a command multiple nesting layers deep you will be reliant upon this method.
So lern it the right way from the get go.

Also after a short learning period you do not want to go back to using the clonky F-Key method any more.
Trust me.

Here are some of the commands that I use the most.

Escape Sequence Command Function
Ctrl+a ? Lists all commands
Ctrl+a c Creates a new window
Ctrl+a k Closes (kill) a windows
Ctrl+a <Number> Jumps to the window <Number>
Ctrl+a | Horizontally splits the shell
Ctrl+a % Vertically spits the shell
Ctrl+a , Renames the window

Cheers,
Ori


01_Byobu introduction

Byobu is a terminal miltiplexer and makes working with the shell way more effective.
It is already installed on recent ubuntu desktop and server versions.

You can install it easily using apt or yum on other distros that do not come with byobu preinstalled as it is part of most repos.

Byobu startet Ihr von der Kommandozeile aus mit dem gleichnamigen Befehl ohne irgendwelche Parameter.
You start byobu from the shell.

byobu

The first thing you will probably notice is that the color scheme of the terminal has changed, your prompt looks different and there is a footer bar.

This bar at the bottom of the shell is showing the following from left to right:

  • Linux disribution and version, in this case Ubuntu 16.04
  • The active windows (I will get to that in a second), currently the windows 0 that has the name "-"
  • Amount of missing updates, the round arrow indicates that there are currently no updates missing
  • Load Average
  • Informations regarding the CPU / Cores
  • Available RAM and the current RAM usage
  • Date and time

Hiding these infos or adding different ones can be done in the byobu config files.

Windows

In the beginning I mentioned that byobu is a multiplexer.
If you press F2 you will open a new window.

The lower bar now shows that Window 0 is not highlighted anymore and there is now a highlighted window 1.
Highlighted means that you are currently working in that window.

Using F3 and F4 you can navigate in those windows.
If we now add a new window using F2, type different things in all three windows and cycle through them it looks something like this.

If you want to rename a window you can do it by pressing F8.

That should be sufficient for a first look.
I will go into more detailed what makes this tool so powerful in later posts.

Cheers,
Ori


VMware: How to save lost VMs

In this post I will show you how you can save lost VMs.
Especially those that claim they cannot find thier hard drive after a firmwareupgrade.

However if you take a look at what file on the storage that hard drive points to the file is still there.
If you now disconnect the harddrive and add a "existing hard drive" you cannot select it.

What files are relevant

To address the issue we will first have to look at what files we will have to touch

  • .vmdk - Pointer to the virtual hard drive
  • -flat.vmdk - the actual hard drive file
  • .vmx - The file describing the VM

Enable SSH

You will need to enable SSH on the hypervisor to apply the fix
Since it is just that intuitive, here a little graphic.

Setup a new VM

Create a new VM and name it what ever you want (different then the original) and give it a 10GB Harddrive with the same hardware configuration as the defect VM.
You do not want the a server that expects two network cards to boot up finding only one or be unable to start a database as it suddenly has way less RAM available.

Check how much storage is left and that a copy of the VM fits cosily into the remaining space.
(A good value to go by as proven to be 10% of the Storage should remain unused. If your storage is 10TB or more, 5% free should do.)

In this case the size of the VM is 250GB and I have about 2TB left.

Copy the hard drive

Connect to the ESXi host using SSH and navigate to the directory of your new VM.
As the storage in this example is named "Storage" the command looks like this:

cd /vmfs/volumes/Storage

Do not wonder if you prompt is showing a different path.
Storage is just a softlink pointing to the real path of the storage in the /volumes directory.

Now go ahead and delete the current -flat.vmdk of the newly created VM.

rm ./<Name der Neuen VM>-flat.vmdk

Then you copy the -flat.vmdk of the old VM into the directory of the current new one and give it the name of the -flat.vmdk you just deleted.

cp ../<NAME OF THE OLD VM>/<NAME OF THE OLD VM>-flat.vmdk ./<NAME OF THE NEW VM>-flat.vmdk

If the name of the old VM were "broken" and the name of the new VM "working" the command would look like this.

cp ../broken/broken-flat.vmdk ./working-flat.vmdk

The prompt will freeze until the copy process is complete.
This can take a while, depending on the read/write speed of the storage.

In my case it took over 1 hour to copy 250GB...
DO NOT turn on the VM once the copy process has finished.

 

Enlarge the Harddrive

The .vmx currently describes the connected harddive as 10GB in size.
Go to the settings of the new VM and enlarge the harddrive to the original size +10GB.

You should now be able to start the VM.
If you are starting a windows server it can take quite some time on the first bootup after the restore.

The server will start with DHCP as it detected a new unconfigured network card.
You cannot give the server the same IP it has before as there are still offline-adapters on the server blocking that IP.

To avoid unnecessary pain I suggest removing ALL network adapters from the VM and then go the to device management.

devmgmt.msc

Here you have to enable "show hidden objects".

Go ahead and deinstall all VMware networkadapters.

Next you will have to clean up the registry...
Start the registry editor.
(Windows + R ->  regedit)

Delete the RegistryKeys at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\NetworkCards\

Shut down the server, add the needed network adapters and then finally start it to use it.

Cheers,
Ori


Office 365 Offline Installer

A office 365 offline installer is a nice thing to have.
Nice for the customer that might have a slow internet connection on the one hand.
And on the other hand nice to have included in a base image that you can roll out to new devices.

I want to give you a short rundown on how to create one.
Download the Office Deployment Tool.

Then go to config.office.com and create a configuration XML.
You can define settings like the installed office language, license, processor architecture etc.

Once you have turned all the switches and knobs the way you want then, you can export this into a XML file.

Start a CMD and run the setup.exe (Office Deployment Tool) with the parameter /download <Path to the XML file>.

This will download a Folder "Office" to the location of the Setup.exe
Copy that folder and the setup.exe into the same folder on the target machine and run the setup.exe with the parameter /configure <Path to the XML file>.

This will start a offline Office installation.

Cheers,
Ori


Restoring the SA user password of a MS SQL Instance

Before making any changes to the server, please create a backup.
In case you are working on a VM I recommend cloning it before trying this on a live instance.

Download the PS Tools, you are going to need them.

Login using a DomAdmin to the SQL Server and create a local administrator.

net user restoresql /add
net localgroup Administrators /ADD

Keep in mind that the local group name depends on the locale... m(
You can of-course use the MMC Snap-In for local groups and user for this as well.

Then start the SQL Server Manager and connect to the SQL Instance using Windows authentication.
Rightclick on SQL Instanz > Security > Logins and select new login... and select the local admin you just created.

Do not try and give this account any additional rights at this point.
It will fail as you do not have sufficient permissions.

Once this is done log off and log back in using the local admin.

Run the  SQLServerManagerXX.msc located in the C:\Windows\SysWOW64\SQLServer folder
The filename depends on the SQL Version you are running.

Select the SQL Instance that you do not have the SA Password for, stop it and then go to preferences.

We will add the start parameter -m to that instance, forcing it to start in the single user mode.
Start it the same way you stopped it.

Now we need to get a SQL Server Manager running using windows Authentication as NT-AUTHORITY\SYSTEM.
This is where the PStools come into play.

Look at what file the shortcut of the SQL Server Manager is pointing to and copy that path.

Run a administrative CMD and switch into the path of the PS Tools folder.
Here you will run psexec.exe with the parameters -i and -s "Path to the Ssms.exe".

Depending on the MS SQL Version you are running, itwill look something like this.

psexec.exe -i -s "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\ManagementStudio\Ssms.exe"

Now a SQL Management Studio in the user context of NT-AUTHORITY\SYSTEM gets started and you can use windows authentication.

You should notice that you will now see a lot more accounts in the login part of the Instance.
From my understanding this should be enough to reset the SA password, however I could not get it to run.
That is why I did go the extra mile of creating the local admin and adding it to the instance.

Go to the restoresql user, Rightklick > Settings > Serverroles and give him at least sysadmin.

Then go to File > Save all and quit the SQL Server Management Studio.

Now go back to the SQL Server Configuration Manager > stop the SQL Server > remove the parameter -m and start the server agin. I think I do not need to screenshot that part again. Start the SQL Server Management Studio again using the windows authentication of the local admin.

You can now change the Password of the SA User.

Do not forget to save all Alles speichern and try logging in as the SA user.

And now you are SA.

I hope this can one day help someone.

Cheers,
Ori

 


Migrating a calendar from one nextcloud to another

This article will show you how to download a calendar from a nextcloud and upload it to another.

Export

First login to the nextcloud that you want to export the calendar from and change to the calendar app.
Klick on the three dots on the left hand side and select Download.

The calendar will be downloaded to your machine as a .ics file.
If you plan on exporting multiple calendars, you should rename these files.

Import

If you have exported all the calendars that you want to export, login to the new nextlcloud.
Change to the calendar app and go to Settings & Import in in the lower left hand corner.

The settings will expand and you can choose Import Calendar.
Upload the .ics file you have previously downloaded.

In the window opening after the upload you can decider if you want to import the calendar items into a existing calendar or create a new one.
I choose New calendar in this example.

By clicking on the green check symbol the import process starts.
Please do not interrupt it.

Afterwards the import should be complete.
Please keep in mind that your new calendar is not shared with anyone on the new cloud yet.
If you did share it on the old NextCloud and want to share it on this one as well, you will have to share it again.

Cheers,
Ori