Martin's Tex-Blog

Posts on programming and generally technical topics

Archive for the ‘Linux’ Category

Using private/public key for authentication in Putty

leave a comment »

If you want to make your life easier and no longer need to enter password, follow these steps:

1. Use PuttyGen to generate public/private keys and save them to local folder as my_key.ppk and
2. Store my_key.ppk to ~\.ssh\authorized_keys2 file, remember to convert it to openssh format:
– remove two first lines and one last line
– add ssh-rsa followed with one space
3. In putty specify my_key.ppk in Connection->SSH->Auth setting
4. You might also need to:
$ chmod 600 ~/.ssh/authorized_keys2
$ chmod 700 ~/.ssh/
on server

You might also add my_key.ppk to Putty Pageant which will provide your key automatically to Putty.

Now if all is working ok, you might want to add your login username to Conenction->Data->Auto-login username editbox. No more username/login prompts.

This procedure is required by some other software like TortoiseGIT.


Written by Marcin

December 10, 2011 at 11:13 pm

Posted in Linux

Advanced serialization tips

leave a comment »

Seralization knowledge not fully covered by official training kit.  These are actually notes from CLR via C# chapter 24.

1. SoapFormatter as of .NET 3.5 is obsolete, for production code use XmlSerializer or DataContractSerializer.
2. Instances can be deep cloned using binary serialization, remember to set:
bin_formatter.Context = new StreamingContext(StreamingContextStates.Clone);
3. You can serialize multiple objects to single stream
4. If You serialize instances of objects which are located in custom loaded assemblies (using LoadFrom), then SerializationExceptin might be thrown. To load assembly when requested, implement delegate that matches System.ResolveEventHandler and register this method with System.AppDomain’s AssemblyResolve event just before deserialization and remove it after it.
5. If some of the objects in the graph are not serializable, then exception will be thrown. It is thrown not before serialization, it can happen any time during it. This can cause resulting stream to contain corrupt data. In order to fail gracefully, serialize to memory stream, and if all is ok, send it to network stream etc.
6. The SerializableAttribute custom attribute may be applied to reference types (class), value types (struct), enumerated types (enum), and delegate types (delegate) only. But since enumerated types and delegates are serializable by default, it makes no sense to add this attribute to them.
7. Serializable attribute is not being inherited, if super class is non serializable then subclasses are not either.
8. Do not set Serializable to automatically generated properties, their names can change during compilation, making it not possible to deserialize.
9. Formatters makes use of FormatterServices class for serialization and deserialization, steps are as follows:

– Call FormatterServices.GetSerializableMembers to get MemberInfo[].
– Then call FormatterServices.GetObjectData to get array of values for each MemberInfo instance in the above array.
– Store assembly identity and type’s full name.
– Store each member, their type, name and value.

– Load assembly identity information and if required load it. Call FormatterServices.GetTypeFromAssembly. This call returns System.Type that represents object to be deserialized.
– Call FormatterServices.GetUninitializedObject with previously returned System.Type, this returns an non-constructed object, with fields set to zero values.
– Now call FormatterServices.GetSerializableMembers to get MemberInfo[]. Those members will need to be deserialized.
– Formatter creates object data from the stream, those will be values of our members.
– With all prepared data call FormatterServices.PopulateObjectMembers, it requires reference to object, MemberInfo[] and Object[] – with values (deserialized in step above).

10. Implementation of ISerializable interface (to get freedom of how serialization happens and get rid of slow reflection), requires implementing its methods in each subclass, and also calling in them, super class versions.
11. Always add followng attribute to your ISerializable.GetObjectdata: [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]. This will prevent outside code from using this method in some malicious ways.
12. When using SerializationInfo class in c-tor, you should call the same Get* methods types as in ISerializable.GetObjectData. If there is a mismatch when deserializing given data, framework will try to convert it with IFormatterConverter, which internally calls System.Convert for core types. For other types it uses type’s IConvertible implementation.
13. SerializationInfo also provides enumerator, which returns SerializationEntry instances.
14. To custom serialize class which base type does not implement ISerializable, use this.GetType().BaseType, and serialize/deserialize it manually. This might be not possible with private fields.
15. Serializing a Type as a different Type, and Deserializing as a different object. This is of use when using singletons, DBNull object. For serialization:
– Add to ISerialization.GetObjectData, SerializationInfo.SetType() method call. As a parameter specify type of custom class that derives from IObjectReference.
16. Serialization surrogates: this is a technique that allows to serialize types not designed for serialization, to deserialize type to a new version, etc.. It is realized by createing class that implements ISerializationSurrogate interface. Its methods GetObjectData and SetObjectData are used for serialization and deserialization. In orderd to let Formatter know about our serializing surrogate implementation, create and initilize SurrogateSelector class and set it to Formatters SurrogateSelector property.
17. The BinaryFormatter class has a bug that prevents a surrogate from serializing objects with references to each other. For fix look into CLR Via C#.
18. Finally there is a technique to deserialize data to a different object than the one used during serialization. This is of use when new version of type is created, or type is moved to other assembly, client want to deserialize data from server to different local type. To use it implement SerializationBinder abstract class, and set it to Formatter’s Binder property.

Below are notes from other sources:

19. ObjectManager tracks deserialized objects. Formatter uses it to check if given reference is backward reference – its object was already deserialized, or it is forward reference – instance was not yet deserialized – this requires recording fixup with ObjectManager. Fixup means that reference will be assigned correct object in the future when actual object will get deserialized.
20. Marshaling is the process of packaging and sending remote procedure calls across process and application boundaries using serialization and deserialization.

Written by Marcin

March 27, 2011 at 4:50 pm

Posted in Linux, MCTS 70-536

Tagged with

putty and Ctrl + s that blocks screen

leave a comment »

When you press Ctrl + s under putty, then your linux session will freeze and screen will not update. In my case I mostly had to restart my session which was quite annoying even though I use screen. Quicker solution is to press Ctrl + q. This is what many websites/blogs will tell you.

I am writing it here just to remind me of it, since I constantly forget that trick.

Written by Marcin

December 9, 2010 at 11:05 pm

Posted in Linux, Uncategorized

Configure firefox to use proxy using ssh

leave a comment »

If you own some remote server access over ssh, then you can easily tunell all your http request over it. Under linux ssh tool is available by default, under windows its best to install Cygwin with ssh. After that all you have to do is issue following command:

$ ssh -ND localhost:8080 $USER@$REMOTE_SERVER

where localhost:8080 means that ssh will bind to localhost on port 8080, $USER is the name of your user account on remote server $REMOTE_SERVER.

after that you need to configure firefox to. Under firefox : enter Tools->Options->Advanced->Network->Settings, choose manual configuration and fill “Host Socks” with localhost:8080.

and thats all

Written by Marcin

November 18, 2009 at 7:40 am

Posted in Linux

Compiling synergy on OpenSuse 11.1 x64 with gcc 4.3.2

leave a comment »

Here are some hints on how to make synergy work on OpenSuse 11.1.

1. Fix bugs in code that originate from using gcc version 4.3.2, this were all because of missing header files, like cstdlib, memory, string.h. These are no longer being auto added by other general headers and must be added manually.

2. Later on I had to disable compiler errors on warnings. Otherwise I would have to make more code fixes, these is probably also caused by newer version of gcc than the one used by synergy developers.

3. Step 2 – required changes in, which resulted in errors with autoconf and automake. I was missing aclocal-1.6 and automake-1.6, but I did have newer versions aclocal-1.10 and automake-1.10, so the simple solution was to symlink new binary file names to older file names.

after that synergyc compiled properly, and did properly connect to my synergy server located on windows box.

Written by Marcin

September 27, 2009 at 6:27 pm

Posted in Linux

How do you use your linux box?

leave a comment »

By that I meant whether you use it normally as a separate operating system on your hard disk, or maybe use it in some fancy way. I would like to describe here how I set up my linux work environment. My main work is under windows os and this wont change in some time, and I really don’t like reseting computer to switch to linux box working in dual boot. The solution was to use VMWare Player with Ubuntu image, I quickly stopped using VMWare window which is from my perspective not user friendly, and installed No Machine client, whose window seamlessly integrates with Windows GUI. Now I can do my programming on linux and windows at the same time. There are still some problems with Samba and accessing windows folders, but I hope to fix it soon.

Written by Marcin

July 7, 2009 at 6:35 am

Posted in Linux

Experiences with update from OpenSuse 11 to 11.1 (x86_64)

leave a comment »

Update went without any problems, following problems appeared later on:

1. After first reboot system hang at “Starting Service Jexec”. Recomended solution is to disable this service, to do it you can use your DVD disk and enter “Recovery System” from its start menu, then mount linux partition to be able to enter yast, in my case it was:

mount /dev/sda1 /mnt
mount -o bind /proc /mnt/proc
mount -o bind /sys /mnt/sys
mount -o bind /dev /mnt/dev
chroot /mnt

to find your partition use:

fdisk -l

after that disable jexec in yast : System->System Services->System Services (Runlevel)

2. Later on I could not enter Kde (3.5), the problem was that ATI drivers needed to be reinstalled for new kernel – that was expected. To be able to enter Kde, enter sax2 in shell, this will reset your driver. Then when in Kde you can navigate to Ati website for new driver.

3. Installation of new drivers ( ATI ).

yast2 -i kernel-source make gcc libgcc
shutdown -r now

that was for ATI Mobility Radeon HD 3400 Series for x86_64 architecture. Funny thing is that on ATI website I had to choose non-mobile category, at first I thought I am installing wrong driver for desktop PC.

After reboot it works great, I even have hi resolution view at system startup (after grub), this didn’t work with previous kernel/ATI driver. But I will have to use vga=0 in grub config as I explain in 4 😦

4. Suspend to disk works properly, resume from disk – does not. There seems to be problems with display driver at startup – right after grub. I was able to properly resume only after entering vga=0 in grub config.

Written by Marcin

February 17, 2009 at 6:57 am

Posted in Linux

JungleDisk on OpenSuse as a subversion server

leave a comment »

JungleDisk with Amazon s3 service is a cheap and very comfortable way to store your data online. It allows access on windows, mac and linux. All data can be encrypted locally before sending to server. Since I dont have very fast internet connection, I am still backing up my data locally, yet I found JD + Amazon s3 a great pair to setup subversion server.

Whole idea is to mount jungledisk bucket as a local folder. Then direct all subversion request to file://[path to mounted folder]. Simple as that, yet requires some typing. I have tested this on two machines – one running OpenSuse 10.2 (32bit) and other with OpenSuse 10.3 (64bit). So lets begin…

If your system lack FUSE file system then follow steps 1-3, you can check it by entering ‘modprobe fuse’ in shell, if module exists then nothing will be on output, otherwise you will see an error. Step 2 is also required if you want to allow all users to access s3 storage.

1. Install FUSE file system, it is available from yast2->Software->Software Management.
2. Create file /etc/fuse.conf with one single line:
3. Make fuse module run on system boot, go to yast2->System->/etc/sysconfig Editor then navigate to System->Kernel->MODULES_LOADED_ON_BOOT and enter fuse in edit area. You can also follow jungledisk suggestion: “Edit /etc/sysconfig/kernel and add “fuse” to the MODULES_LOADED_ON_BOOT”

If fuse is configured then its time for jungledisk:

1. Download and unpack jungledisk tarball for your system and copy both junglediskmonitor and jungledisk files to /usr/bin folder
2. Run junglediskmonitor (requires GUI) and configure your s3 and jungledisk access. If successfull then in ~/.jungledisk folder you will see jungledisk-settings.xml file.
3. Open ~/.bash_profile (create if missing) and enter following line:

jungledisk ~/jungledisk -o config=/home/user/.jungledisk/jungledisk-settings.xml -o allow_other

where ~/jungledisk is your mount point (create folder if missing), user is your user name.

Now you can either reboot your machine, to check if all configuration is working. After boot you should be able to see after entering ‘df -h’ following line:

jungledisk 382G 0 382G 0% /home/user/jungledisk

INSTALL file that comes from jungledisk suggests also granting permisons on two executables in following way:
chmod o+rw /dev/fuse
chmod o+rw /usr/bin/fusermount

I actually did not have to do that.

You might encounter following errors from SVN during import, commit:

svn: Invalid changes line in rev-file

The solution is to add additional option : -s at the and off jungledisk command in .bash_profile. This option removes some optimizations that appear to cause that error.

Written by Marcin

February 15, 2009 at 7:56 am

Posted in Linux

Downgrade subversion from 1.5 to 1.4 on OpenSuse 11

leave a comment »

Version 1.5 of subversion will modify your repository structure rendering it not possible to use with version 1.4. Another reason for downgrade to 1.4 version is if you store repositories on jungledisk s3 buckets which does not work good with 1.5 version. So if you need 1.4 version to access your repositories then follow this instructions:

1. Uninstall current subversion package using yast2. Actually I’am not 100% sure if that is needed – whether zypper later on will uninstall it on its own.

2. Add package repositories from older version of OpenSuse:

# zypper addrepo repo10_3

3. Install version 1.4 of subversion:

zypper install -C subversion=1.4.4

This command will list all dependencies that will have to be installed or downgraded, you will be asked for confirmation before proceeding.

Written by Marcin

February 15, 2009 at 7:41 am

Posted in Linux

OpenSuse 11 and 'couldn't resolve host XXX error' in Updater

leave a comment »

If  you encounter this error message while installing or updating software packages then it is not necessary problem with OpenSuse but possibly with your DNS provider. In my situation, updater couldn’t resolve host It appears that my DNS service provider does not have such name in its tables. I was able to resolve its IP name using online ping tool like: After that discovery, it was enough to add a new line to /etc/hosts file :

to fix the problem.

Written by Marcin

January 4, 2009 at 2:11 pm

Posted in Linux