The peanut shells derived porous hard carbons (PSDHCs) by pyrolysis have been investigated as anodes of lithium/sodium batteries (LIBs/NIBs). Directly from the starting peanut shells, 600°C is found to be the favorable pyrolysis temperature for preparation of the PSDHC sample (PSDHC-600) with the best electrochemical performances for LIB applications. Furthermore, from the activated peanut shells in KOH solution, the produced PSDHC-600A by pyrolysis at 600°C is observed to offer greatly enhanced Li+/Na+ ion storages. For LIB applications, PSDHC-600A delivers a retained capacity of 474 mAhg−1 after 400 cycles at 1 Ag−1, larger than 314 mAhg−1 of PSDHC-600. At a high current rate of 5 Ag−1, PSDHC-600A sustains over 10000 cycles with no obvious sign of fade in capacity, and a capacity of 310 mAhg−1 is still retained. For NIB applications, a capacity of 193 mAh g−1 is retained after 400 cycles at 0.25 Ag−1, higher than 130 mAhg−1 of PSDHC-600. Even at 1 Ag−1, PSDHC-600A can be stably cycled over 3000 cycles, and a capacity of 129 mAhg−1 is still retained. In comparison to PSDHC-600, the enhanced electrochemical properties of PSDHC-600A can be attributed to the finer porous structure with the increased percentage of nanoscale pores of diameter less than 2 nm and the larger specific surface area.