Leviticus 25:44-54

44 As for the male and female slaves whom you may have, it is from the nations around you that you may acquire male and female slaves.
45 You may also acquire them from among the aliens residing with you, and from their families that are with you, who have been born in your land; and they may be your property.
46 You may keep them as a possession for your children after you, for them to inherit as property. These you may treat as slaves, but as for your fellow Israelites, no one shall rule over the other with harshness.
47 If resident aliens among you prosper, and if any of your kin fall into difficulty with one of them and sell themselves to an alien, or to a branch of the alien's family,
48 after they have sold themselves they shall have the right of redemption; one of their brothers may redeem them,
49 or their uncle or their uncle's son may redeem them, or anyone of their family who is of their own flesh may redeem them; or if they prosper they may redeem themselves.
50 They shall compute with the purchaser the total from the year when they sold themselves to the alien until the jubilee year; the price of the sale shall be applied to the number of years: the time they were with the owner shall be rated as the time of a hired laborer.
51 If many years remain, they shall pay for their redemption in proportion to the purchase price;
52 and if few years remain until the jubilee year, they shall compute thus: according to the years involved they shall make payment for their redemption.
53 As a laborer hired by the year they shall be under the alien's authority, who shall not, however, rule with harshness over them in your sight.
54 And if they have not been redeemed in any of these ways, they and their children with them shall go free in the jubilee year.