SSH To Box with .PEM

ssh-keygen -t rsa -b 2048 -v

Enter a file name for example “work” and accept other defaults. Two files will get generated, work and work.pub.

rename work to work.pem and put in

copy work.pub to the server you want to ssh to and append it to the file ~/.ssh/authorized_keys (create if needed)

edit your local ~/.ssh/config and add the following inserting the ip address and user name appropriately.

Host work
HostName <host ip address>
IdentityFile ~/.ssh/work.pem
User <user name>

Then to connect simply

ssh work
Advertisements

If you are getting errors like “Plugin blah or one of its dependencies could not be resolved” you may find this useful.

There is an issue with Maven 3.0.3 (and I assume earlier) in that plug-in repositories need to be separately configured from the normal repository. The maven settings file must contain something like this:

<pluginRepositories>
    <pluginRepository>
        <id>nexus-3rdParty</id>
        <name>Snapshots</name>
        <url>http://repo.mycompany.com:8081/nexus/content/repositories/thirdparty</url&gt;
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>   
           

With 3.0.4, maven will pick up the plugin repository information from the repositories configuration.

Reg Edit – take ownership – create explorer meny

Found these reg settings that are very useful and didn't know where to put them for future reference.  So here they are.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\runas]
@="Take Ownership"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\*\shell\runas\command]
@="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F"

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Take Ownership"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d y && icacls \"%1\" /grant administrators:F /t"

gethostbyname or getaddrinfo that doesn’t block

gethostbyname and getaddrinfo block.  There is no way to stop them once they’ve started.  (BTW, getaddrinfo is recommended over gethostbyname as it’s IPv6 compatible.)  This little class will provide a neat way to get the info without blocking.  Classes extra::Thread and extra::auto_HANDLE are thread and and auto handle closing classes respectivly (is that english?).  When the user requires to cancel the request or connect, call m_hostNameGetter.Abort() from within MySocketClass.

The Class:

class CGetAddrInfoThread : private extra::Thread
{
public:
    CGetAddrInfoThread();
    void Abort();
    struct addrinfo *GetAddrInfo(const extra::tstring &host, ULONG nPort);
private:
    extra::auto_HANDLE m_abort;
    extra::tstring m_host;
    ULONG m_port;
    struct addrinfo *m_ret;
    virtual DWORD ThreadProc();
};

The Implementation

CGetAddrInfoThread::CGetAddrInfoThread() :
        m_port(0), m_ret(0), m_abort(0,0,CloseHandle)
{
}
void CGetAddrInfoThread::Abort()
{
    SetEvent(m_abort);
}
struct addrinfo *CGetAddrInfoThread::GetAddrInfo(const extra::tstring &host, ULONG nPort)
{
    if(!m_abort.Valid())
        m_abort = CreateEvent(0,TRUE,FALSE,0);
    m_host = host;
    m_port = nPort;
    m_ret = 0;
    ResetEvent(m_abort
    if(!Create().Valid())
        return 0
    HANDLE handles[] = {ThreadHandle(),m_abort};
    return ((WaitForMultipleObjects(sizeof(handles)/sizeof(handles[0]),
                handles,FALSE,INFINITE)==WAIT_OBJECT_0) ? m_ret : 0);
}
DWORD CGetAddrInfoThread::ThreadProc()
{
    char port[16];
    if(_ultoa_s(m_port,port,10))
        return 0;
    struct addrinfo aiHints;
    memset(&aiHints, 0, sizeof(aiHints));
    aiHints.ai_family = AF_INET;
    aiHints.ai_socktype = SOCK_STREAM;
    aiHints.ai_protocol = IPPROTO_TCP;
    if (::getaddrinfo(CT2CA(m_host.c_str()), port, &aiHints, &m_ret))
        m_ret = 0;
    return 0;
}

Using the class:

void MySocketClass::MyConnectingMethod()
{
    // do stuff
    struct addrinfo *aiList = m_hostNameGetter.GetAddrInfo(host,nPort);
    if(!aiList)
        return 0;
    // do stuff
}