user64569: I have read through a number of posts on here about this error but none seem to solve my problem. I am trying to use Altcoin-cli on my alt-coin (which is an exact clone of the bitcoin source) using my generated Altcoind daemon and Altcoin-cli 
I know that it is an exact copy of bitcoin because I forked it myself (for learning purposes) so the error isn't caused by me breaking some code. Here are the steps I am doing:
1) In one terminal I run Altcoind -daemon -reindex
2) In my Altcoin.conf fine I have this:
rpcuser=barney
rpcpassword=12345
rpcport=22777
listen=1
server=1
dbcache=50
daemon=1
testnet=0
maxuploadtarget=200
txindex=1

3) I then run Altcoin-cli generate 1 -1 in attempt to mine a block. This is where I get the error:
error: couldn't connect to server: unknown (code -1)
(make sure server is running and you are connecting to the correct RPC port)
Also, when I run the cli command, this line appears in the debug.log
keypool reserve 2
I will add my debug.log dump below too, but it looks fine to me. The connection refused errors are the coin attempting to connect to seed nodes that don't exist yet.
DEBUG.LOG Dump
2018-01-04 07:10:51 Bitcoin version v0.1.0.0-0b9d033-dirty
2018-01-04 07:10:51 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1
2018-01-04 07:10:51 Assuming ancestors of block 00000000000000000013176bf8d7dfeab4e1db31dc93bc311b436e82ab226b90 have valid signatures.
2018-01-04 07:10:51 Default data directory /home/veggie/.Teggie
2018-01-04 07:10:51 Using data directory /home/veggie/.Teggie
2018-01-04 07:10:51 Using config file /home/veggie/.Teggie/Teggie.conf
2018-01-04 07:10:51 Using at most 125 automatic connections (1024 file descriptors available)
2018-01-04 07:10:51 Using 32 MiB out of 32 requested for signature cache, able to store 1048576 elements
2018-01-04 07:10:51 Using 0 threads for script verification
2018-01-04 07:10:51 Binding RPC on address 0.0.0.0 port 22777 failed.
2018-01-04 07:10:51 HTTP: creating work queue of depth 16
2018-01-04 07:10:51 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
2018-01-04 07:10:51 HTTP: starting 4 worker threads
2018-01-04 07:10:51 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2018-01-04 07:10:51 Using wallet wallet.dat
2018-01-04 07:10:51 init message: Verifying wallet...
2018-01-04 07:10:51 CDBEnv::Open: LogDir=/home/veggie/.Teggie/database ErrorFile=/home/veggie/.Teggie/db.log
2018-01-04 07:10:51 scheduler thread start
2018-01-04 07:10:51 Bound to [::]:22822
2018-01-04 07:10:51 Bound to 0.0.0.0:22822
2018-01-04 07:10:51 Cache configuration:
2018-01-04 07:10:51 * Using 6.2MiB for block index database
2018-01-04 07:10:51 * Using 8.0MiB for chain state database
2018-01-04 07:10:51 * Using 35.8MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2018-01-04 07:10:51 init message: Loading block index...
2018-01-04 07:10:51 Wiping LevelDB in /home/veggie/.Teggie/blocks/index
2018-01-04 07:10:51 Opening LevelDB in /home/veggie/.Teggie/blocks/index
2018-01-04 07:10:51 Opened LevelDB successfully
2018-01-04 07:10:51 Using obfuscation key for /home/veggie/.Teggie/blocks/index: 0000000000000000
2018-01-04 07:10:51 Wiping LevelDB in /home/veggie/.Teggie/chainstate
2018-01-04 07:10:51 Opening LevelDB in /home/veggie/.Teggie/chainstate
2018-01-04 07:10:51 Opened LevelDB successfully
2018-01-04 07:10:51 Wrote new obfuscate key for /home/veggie/.Teggie/chainstate: 2e49fc905edaf50c
2018-01-04 07:10:51 Using obfuscation key for /home/veggie/.Teggie/chainstate: 2e49fc905edaf50c
2018-01-04 07:10:51 Initializing databases...
2018-01-04 07:10:51 init message: Verifying blocks...
2018-01-04 07:10:51  block index              15ms
2018-01-04 07:10:51 CTxMemPool::ReadFeeEstimates(): unable to read policy estimator data (non-fatal)
2018-01-04 07:10:51 init message: Loading wallet...
2018-01-04 07:10:51 nFileVersion = 10000
2018-01-04 07:10:51 Keys: 103 plaintext, 0 encrypted, 103 w/ metadata, 103 total
2018-01-04 07:10:51  wallet                    6ms
2018-01-04 07:10:51 setKeyPool.size() = 101
2018-01-04 07:10:51 mapWallet.size() = 0
2018-01-04 07:10:51 mapAddressBook.size() = 1
2018-01-04 07:10:51 Reindexing block file blk00000.dat...
2018-01-04 07:10:51 UpdateTip: new best=0000794e30ec87650feebfdc5c39c51927ebb8407129ed5e93375dd825e50380 height=0 version=0x00000001 log2_work=17 tx=1 date='2017-12-06 14:20:46' progress=1.000000 cache=0.0MiB(0tx)
2018-01-04 07:10:51 mapBlockIndex.size() = 1
2018-01-04 07:10:51 nBestHeight = 0
2018-01-04 07:10:51 init message: Loading addresses...
2018-01-04 07:10:51 Loaded 2 addresses from peers.dat  1ms
2018-01-04 07:10:51 init message: Loading banlist...
2018-01-04 07:10:51 init message: Starting network threads...
2018-01-04 07:10:51 init message: Done loading
2018-01-04 07:10:51 msghand thread start
2018-01-04 07:10:51 opencon thread start
2018-01-04 07:10:51 addcon thread start
2018-01-04 07:10:51 dnsseed thread start
2018-01-04 07:10:51 net thread start
2018-01-04 07:10:51 torcontrol thread start
2018-01-04 07:10:51 Loaded 1 blocks from external file in 210ms
2018-01-04 07:10:51 Reindexing finished
2018-01-04 07:10:51 Imported mempool transactions from disk: 0 successes, 0 failed, 0 expired
2018-01-04 07:10:53 connect() to 207.246.105.211:22822 failed after select(): Connection refused (111)
2018-01-04 07:10:55 connect() to 45.63.111.147:22822 failed after select(): Connection refused (111)
2018-01-04 07:10:58 connect() to 45.63.111.147:22822 failed after select(): Connection refused (111)
2018-01-04 07:11:00 connect() to 207.246.105.211:22822 failed after select(): Connection refused (111)


user5486: Did you confirm that your user trying ti use bitcoin-cli has ownership permissions on the .bitcoin directory?  That was what gave me trouble.  To fix, I ran:
sudo chown username:username /directory/location/of/.bitcoin

64569: <p>I have read through a number of posts on here about this error but none seem to solve my problem. I am trying to use Altcoin-cli on my alt-coin (which is an exact clone of the bitcoin source) using my generated Altcoind daemon and Altcoin-cli </p>

<p>I know that it is an exact copy of bitcoin because I forked it myself (for learning purposes) so the error isn't caused by me breaking some code. Here are the steps I am doing:</p>

<p>1) In one terminal I run <code>Altcoind -daemon -reindex</code></p>

<p>2) In my Altcoin.conf fine I have this:</p>

<pre><code>rpcuser=barney
rpcpassword=12345
rpcport=22777
listen=1
server=1
dbcache=50
daemon=1
testnet=0
maxuploadtarget=200
txindex=1
</code></pre>

<p>3) I then run <code>Altcoin-cli generate 1 -1</code> in attempt to mine a block. This is where I get the error:</p>

<p><code>error: couldn't connect to server: unknown (code -1)
(make sure server is running and you are connecting to the correct RPC port)</code></p>

<p>Also, when I run the <code>cli</code> command, this line appears in the <code>debug.log</code></p>

<p><code>keypool reserve 2</code></p>

<p>I will add my debug.log dump below too, but it looks fine to me. The <code>connection refused</code> errors are the coin attempting to connect to seed nodes that don't exist yet.</p>

<p><strong><em>DEBUG.LOG Dump</em></strong></p>

<pre><code>2018-01-04 07:10:51 Bitcoin version v0.1.0.0-0b9d033-dirty
2018-01-04 07:10:51 InitParameterInteraction: parameter interaction: -whitelistforcerelay=1 -&gt; setting -whitelistrelay=1
2018-01-04 07:10:51 Assuming ancestors of block 00000000000000000013176bf8d7dfeab4e1db31dc93bc311b436e82ab226b90 have valid signatures.
2018-01-04 07:10:51 Default data directory /home/veggie/.Teggie
2018-01-04 07:10:51 Using data directory /home/veggie/.Teggie
2018-01-04 07:10:51 Using config file /home/veggie/.Teggie/Teggie.conf
2018-01-04 07:10:51 Using at most 125 automatic connections (1024 file descriptors available)
2018-01-04 07:10:51 Using 32 MiB out of 32 requested for signature cache, able to store 1048576 elements
2018-01-04 07:10:51 Using 0 threads for script verification
2018-01-04 07:10:51 Binding RPC on address 0.0.0.0 port 22777 failed.
2018-01-04 07:10:51 HTTP: creating work queue of depth 16
2018-01-04 07:10:51 Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.
2018-01-04 07:10:51 HTTP: starting 4 worker threads
2018-01-04 07:10:51 Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2018-01-04 07:10:51 Using wallet wallet.dat
2018-01-04 07:10:51 init message: Verifying wallet...
2018-01-04 07:10:51 CDBEnv::Open: LogDir=/home/veggie/.Teggie/database ErrorFile=/home/veggie/.Teggie/db.log
2018-01-04 07:10:51 scheduler thread start
2018-01-04 07:10:51 Bound to [::]:22822
2018-01-04 07:10:51 Bound to 0.0.0.0:22822
2018-01-04 07:10:51 Cache configuration:
2018-01-04 07:10:51 * Using 6.2MiB for block index database
2018-01-04 07:10:51 * Using 8.0MiB for chain state database
2018-01-04 07:10:51 * Using 35.8MiB for in-memory UTXO set (plus up to 286.1MiB of unused mempool space)
2018-01-04 07:10:51 init message: Loading block index...
2018-01-04 07:10:51 Wiping LevelDB in /home/veggie/.Teggie/blocks/index
2018-01-04 07:10:51 Opening LevelDB in /home/veggie/.Teggie/blocks/index
2018-01-04 07:10:51 Opened LevelDB successfully
2018-01-04 07:10:51 Using obfuscation key for /home/veggie/.Teggie/blocks/index: 0000000000000000
2018-01-04 07:10:51 Wiping LevelDB in /home/veggie/.Teggie/chainstate
2018-01-04 07:10:51 Opening LevelDB in /home/veggie/.Teggie/chainstate
2018-01-04 07:10:51 Opened LevelDB successfully
2018-01-04 07:10:51 Wrote new obfuscate key for /home/veggie/.Teggie/chainstate: 2e49fc905edaf50c
2018-01-04 07:10:51 Using obfuscation key for /home/veggie/.Teggie/chainstate: 2e49fc905edaf50c
2018-01-04 07:10:51 Initializing databases...
2018-01-04 07:10:51 init message: Verifying blocks...
2018-01-04 07:10:51  block index              15ms
2018-01-04 07:10:51 CTxMemPool::ReadFeeEstimates(): unable to read policy estimator data (non-fatal)
2018-01-04 07:10:51 init message: Loading wallet...
2018-01-04 07:10:51 nFileVersion = 10000
2018-01-04 07:10:51 Keys: 103 plaintext, 0 encrypted, 103 w/ metadata, 103 total
2018-01-04 07:10:51  wallet                    6ms
2018-01-04 07:10:51 setKeyPool.size() = 101
2018-01-04 07:10:51 mapWallet.size() = 0
2018-01-04 07:10:51 mapAddressBook.size() = 1
2018-01-04 07:10:51 Reindexing block file blk00000.dat...
2018-01-04 07:10:51 UpdateTip: new best=0000794e30ec87650feebfdc5c39c51927ebb8407129ed5e93375dd825e50380 height=0 version=0x00000001 log2_work=17 tx=1 date='2017-12-06 14:20:46' progress=1.000000 cache=0.0MiB(0tx)
2018-01-04 07:10:51 mapBlockIndex.size() = 1
2018-01-04 07:10:51 nBestHeight = 0
2018-01-04 07:10:51 init message: Loading addresses...
2018-01-04 07:10:51 Loaded 2 addresses from peers.dat  1ms
2018-01-04 07:10:51 init message: Loading banlist...
2018-01-04 07:10:51 init message: Starting network threads...
2018-01-04 07:10:51 init message: Done loading
2018-01-04 07:10:51 msghand thread start
2018-01-04 07:10:51 opencon thread start
2018-01-04 07:10:51 addcon thread start
2018-01-04 07:10:51 dnsseed thread start
2018-01-04 07:10:51 net thread start
2018-01-04 07:10:51 torcontrol thread start
2018-01-04 07:10:51 Loaded 1 blocks from external file in 210ms
2018-01-04 07:10:51 Reindexing finished
2018-01-04 07:10:51 Imported mempool transactions from disk: 0 successes, 0 failed, 0 expired
2018-01-04 07:10:53 connect() to 207.246.105.211:22822 failed after select(): Connection refused (111)
2018-01-04 07:10:55 connect() to 45.63.111.147:22822 failed after select(): Connection refused (111)
2018-01-04 07:10:58 connect() to 45.63.111.147:22822 failed after select(): Connection refused (111)
2018-01-04 07:11:00 connect() to 207.246.105.211:22822 failed after select(): Connection refused (111)
</code></pre>
 5486: <p>Did you confirm that your user trying ti use bitcoin-cli has ownership permissions on the .bitcoin directory?  That was what gave me trouble.  To fix, I ran:</p>

<p><code>sudo chown username:username /directory/location/of/.bitcoin</code></p>
