You can't do it with commandline, which may be fortunate as that wouldn't be a programming problem and thus not really ontopic for SO. So here's a minimal programmed example:
/* SO58667890 19nov04 PKCS8 attribute */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/asn1.h>
#include <openssl/err.h>
#include <openssl/objects.h>
#include <openssl/pem.h>
#include <openssl/pkcs12.h>
#include <openssl/x509.h>
void err (const char * s, int n){ fprintf(stderr, "%s:%d\n", s,n); ERR_print_errors_fp (stderr); exit(1); }
int main (int argc, char** argv){
if( argc < 4 ){ fprintf(stderr, "Usage: %s privkey.pem attrname attrvalue\n"); return 0; }
int rv;
BIO *bio = BIO_new_file (argv[1],"r");
if( !bio ) err("BIO_new_file-r",0);
EVP_PKEY *pkey = PEM_read_bio_PrivateKey (bio, NULL, NULL,NULL);
if( !pkey ) err("PEM_read_bio_PrivateKey",0);
PKCS8_PRIV_KEY_INFO *p8inf = EVP_PKEY2PKCS8 (pkey);
if( !p8inf ) err("EVP_PKEY2PKCS8",0);
int nid = OBJ_txt2nid (argv[2]);
if( nid == NID_undef ) err("OBJ_txt2nid",nid);
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
rv = PKCS8_pkey_add1_attr_by_NID (p8inf, nid, V_ASN1_IA5STRING, (unsigned char*)argv[3], strlen(argv[3]));
if( !rv ) err("PKCS8_pkey_add1_attr_by_NID",rv);
#else
if( !X509at_add1_attr_by_NID (&p8inf->attributes, nid, V_ASN1_IA5STRING, (unsigned char*)argv[3], strlen(argv[3])) )
err("X509at_add1_attr_by_NID",0);
#endif
bio = BIO_new_file (argv[1],"w");
if( !bio ) err("BIO_new_file-w",0);
rv = PEM_write_bio_PKCS8_PRIV_KEY_INFO (bio, p8inf);
if( !rv ) err("PEM_write_bio_PKCS8info",rv);
rv = BIO_free(bio);
if( !rv ) err("BIO_free",rv);
return 0;
}
However, as Maarten commented, these attributes are very rarely used. I've seen at least one case here where Java didn't implement them at all. In the PKI world, including S/MIME and SSL/TLS, you usually have an X.509 (or PKIX) certificate for the publickey matching your privatekey, and the certificate has lots of useful information about the identity of the owner and authorized usage of the key -- and this information is in a form programs largely understand and can use (although there are now and then issues with one party or system creating a new certificate extension that isn't understood by another party or system). For example, when you look in Windows certmgr or MacOS keychain, you don't see a privatekey as such; you see a certificate with a privatekey attached to it.