A compressor, comprising: a motor including a rotor; a shaft portion including a shaft main body that is coupled to the rotor; and a compression mechanism unit coupled to the shaft main body and configured to compress refrigerant by use of a driving force of the motor transmitted through the shaft main body, the rotor including a first through hole and a first keyway that is formed on an inner circumferential portion and extends along a direction in which the first through hole passes through, the inner circumferential portion corresponding to a wall surface portion that defines the first through hole, the shaft main body including a stepped portion, a male screw portion, and a second keyway that is formed on a part of an outer circumferential portion of the shaft main body that is between the stepped portion and the male screw portion and extends along an axial direction of the shaft main body, a part of the shaft main body that is between the stepped portion and the male screw portion being inserted in the first through hole of the rotor, the shaft portion including a key that is inserted in the first keyway of the rotor and the second keyway of the shaft main body, the key having a longer length than does the rotor in the direction in which the first through hole passes through, a spacer including a second through hole in which a part of the shaft main body that is between the stepped portion and the male screw portion is inserted, and a third keyway that is formed on an inner circumferential portion of the spacer and extends along a direction in which the second through hole passes through, the inner circumferential portion corresponding to a wall surface portion that defines the second through hole, the key being inserted in the third keyway, the spacer being located at at least one of a part between the stepped portion of the shaft main body and the rotor or a part between the male screw portion of the shaft main body and the rotor, and a nut in which the male screw portion of the shaft main body is screwed, the nut sandwiching and fixing the rotor and the spacer with the stepped portion of the shaft main body. a motor including a rotor; a shaft portion including a shaft main body that is coupled to the rotor; and a compression mechanism unit coupled to the shaft main body and configured to compress refrigerant by use of a driving force of the motor transmitted through the shaft main body, the rotor including a first through hole and a first keyway that is formed on an inner circumferential portion and extends along a direction in which the first through hole passes through, the inner circumferential portion corresponding to a wall surface portion that defines the first through hole, the shaft main body including a stepped portion, a male screw portion, and a second keyway that is formed on a part of an outer circumferential portion of the shaft main body that is between the stepped portion and the male screw portion and extends along an axial direction of the shaft main body, a part of the shaft main body that is between the stepped portion and the male screw portion being inserted in the first through hole of the rotor, the shaft portion including a key that is inserted in the first keyway of the rotor and the second keyway of the shaft main body, the key having a longer length than does the rotor in the direction in which the first through hole passes through, a spacer including a second through hole in which a part of the shaft main body that is between the stepped portion and the male screw portion is inserted, and a third keyway that is formed on an inner circumferential portion of the spacer and extends along a direction in which the second through hole passes through, the inner circumferential portion corresponding to a wall surface portion that defines the second through hole, the key being inserted in the third keyway, the spacer being located at at least one of a part between the stepped portion of the shaft main body and the rotor or a part between the male screw portion of the shaft main body and the rotor, and a nut in which the male screw portion of the shaft main body is screwed, the nut sandwiching and fixing the rotor and the spacer with the stepped portion of the shaft main body.