Problem with Bitcoin Core’s regression test mode I have started bitcoin daemon with -regtest flag. The output was 


  Bitcoin server starting


But, when I run

bitcoin-cli -regtest generate 101


command, it shows 


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


How this happens?
Try changing port number in bitcoin.conf.
open file

nano ~/.bitcoin/bitcoin.conf


add new line


  rpcport=18332;


save the file and restart bitcoind