אהבה
הלכות תפילין ומזוזה וספר תורה
פרק ה
Ahavah
Tefillin, Mezuzah, and Sefer Torah
Chapter 5

Halacha

הלכה א
כֵּיצַד כּוֹתְבִין אֶת הַמְּזוּזָה. כּוֹתְבִין שְׁתֵּי פָּרָשִׁיּוֹת (דברים ו ד) ״שְׁמַע״ (דברים יא יג) ״וְהָיָה אִם שָׁמֹעַ״ עַל דַּף אֶחָד בִּירִיעָה אַחַת וְעוֹשֶׂה לָהּ רֶוַח מִלְּמַטָּה וְרֶוַח מִלְּמַעְלָה כְּמוֹ חֲצִי צִפֹּרֶן. וְאִם כְּתָבָהּ בִּשְׁנַיִם אוֹ בִּשְׁלֹשָׁה דַּפִּין כְּשֵׁרָה. וּבִלְבַד שֶׁלֹּא יַעֲשֶׂנָּה כְּזָנָב אוֹ כְּמוֹ עִגּוּל אוֹ כְּקוּבָּה וְאִם עָשָׂה כְּאַחַת מֵאֵלֶּה פְּסוּלָה. כְּתָבָהּ שֶׁלֹּא עַל הַסֵּדֶר כְּגוֹן שֶׁהִקְדִּים פָּרָשָׁה לְפָרָשָׁה פְּסוּלָה. כְּתָבָהּ בִּשְׁנֵי עוֹרוֹת אַף עַל פִּי שֶׁתְּפָרָן פְּסוּלָה. סֵפֶר תּוֹרָה שֶׁבָּלָה וּתְפִלִּין שֶׁבָּלוּ אֵין עוֹשִׂין מֵהֶן מְזוּזָה. וְלֹא מִן הַגִּלְיוֹנִים שֶׁל סֵפֶר תּוֹרָה אֵין כּוֹתְבִין עָלָיו מְזוּזָה לְפִי שֶׁאֵין מוֹרִידִין מִקְּדֻשָּׁה חֲמוּרָה לִקְדֻשָּׁה קַלָּה:
כסף משנה
1.
How is a mezuzah written?1Sefer HaMitzvot (Positive Commandment 15) and Sefer HaChinuch (Mitzvah 423) consider the mitzvah of mezuzah to be one of the 613 mitzvot of the Torah. The two portions, Shema and V'hayah im shamo'a, are written on one piece of parchment in a single column.2The Jerusalem Talmud (Megillah 1:9) states that unlike a Torah scroll or tefillin, a mezuzah should be written in a single column. Approximately half a fingernail of space3approximately one centimeter should be left above and below [the writing].4Also, a small amount of parchment should be left on the right side for the mezuzah to be rolled closed (Shulchan Aruch, Yoreh De'ah 288:1).
Should one write [a mezuzah] in two or three columns, it is acceptable,5although this is not the desired form as long as it not written tail-shaped,6i.e., wider above than below, the top lines being longer than the bottom ones in a circle,7This word is not found in our text of Menachot 31b, the source for this halachah. or tent-shaped.8i.e., wider below than above, the bottom lines being longer than the top ones. If it was written using any of these forms, it is not acceptable.9Menachot 31b.
If it was not written in order10e.g., one wrote the passage [V'hayah im shamo'a] before the passage [Shema] - it is not acceptable. - Furthermore, if even one letter from a mezuzah was not written in order, the mezuzah is unacceptable (Shulchan Aruch, Yoreh De'ah 288:3).
The Ginat Veradim suggests that the Rambam requires only that the order of the two passages not be reversed, but is not concerned with the order of the letters within the passages themselves. This perspective, however, is not accepted by other authorities, who explain that surely, the Rambam requires order within the passages. He gave the above example only because he felt that it was more important to emphasize that even if the passages themselves were written in order, if their order was reversed, the mezuzah is not acceptable.
- e.g., one wrote the passage [V'hayah im shamo'a] before the passage [Shema] - it is not acceptable. If one writes a mezuzah on two different parchments, it is not acceptable even if they were sewn together [later].11In his Responsa (213), Rabbi Akiva Eiger writes that if the parchments were sewn together before the passages were written upon them, the mezuzah is acceptable.
A mezuzah should not be made from a Torah scroll12i.e., one may not cut the passage, Shema, from a worn Torah scroll and write the passage, V'hayah im shamo'a, on the empty space below it. One may not cut both passages from the Torah scroll since, as explained above, a mezuzah may not be written on two different parchments (Siftei Cohen, Yoreh De'ah 290:1). or tefillin that have become worn,13Though it is possible to cut the two passages from the arm tefillin, it is forbidden to do so. nor should a mezuzah be written on the empty parchment from a Torah scroll,14the empty parchment left as a border above and on the sides of the Torah scroll. The Or Sameach notes thatShabbat 116a questions whether or not these empty portions of parchment have become sanctified with the holiness of a Torah scroll, and does not resolve the issue. Because of the doubt involved, the Rambam rules that in situations where the question of their holiness is raised, one should always take the more stringent perspective. Therefore, in Hilchot Shabbat 23:27, the Rambam rules that they should not be saved from a fire on the Sabbath if the violation of even a Rabbinic transgression is involved (accepting the possibility that they have not become consecrated). In this halachah, this approach requires accepting the possibility that they have been consecrated. because one should not lower an article from a higher level of holiness15As explained in Chapter 10, Halachot 2-5 (see also Hilchot Tefillah 11:14), the holiness of a Torah scroll surpasses that of all other articles. to a lesser one.16Our Sages have established the principle, "One may ascend to a higher level of holiness, but may not descend to a lower one."

הלכה ב
וּמִצְוָה לַעֲשׂוֹת רֶוַח שֶׁבֵּין פָּרָשַׁת (דברים ו ד) ״שְׁמַע״ לִ (דברים יא יג) ״וְהָיָה אִם שָׁמֹעַ״ פָּרָשָׁה סְתוּמָה. וְאִם עָשָׂה אוֹתָהּ פְּתוּחָה כְּשֵׁרָה לְפִי שֶׁאֵינָהּ סְמוּכָה לָהּ מִן הַתּוֹרָה. וְצָרִיךְ לְהִזָּהֵר בְּתָגִין שֶׁבָּהּ. וְאֵלּוּ הֵן הַתָּגִין שֶׁעוֹשִׂין בַּמְּזוּזָה:
כסף משנה
2.
It is a mitzvah to leave a space between the passage Shema and the passage V'hayah im shamo'a, as if it were s'tumah.1S'tumah means "closed." According to the Rambam, it refers to a passage whose first word is always written in the middle of a line in the Torah. See Chapter 8, Halachah 2. In the Torah, V'hayah im shamo'a is s'tumah. If space were left as if it were p'tuchah,2P'tuchah means "open." According to the Rambam, it refers to a passage whose first word is always written at the beginning of a line in the Torah. See Chapter 8, Halachah 1. it is acceptable, since these passages do not follow each other in the Torah.3Note the contrast between this ruling and the Rambam's decision in Chapter 2, Halachah 2, regarding tefillin: "If one wrote a passage which should be s'tumah as p'tuchah or a passage which should be p'tuchah as s'tumah, it is unacceptable."
The Beit Yosef (Orach Chayim 32) explains the difference as follows: In tefillin, there are passages which follow directly after each other in the Torah. Therefore, all the passages must be written as they appear in a Torah scroll. In contrast, the two passages contained in a mezuzah do not follow each other in the Torah. Therefore, there is no absolute requirement for the passages to be written as they appear in the Torah.

One must take care regarding the crowns4See Chapter 2, Halachot 8-9 and Chapter 7, Halachot 8-9. [on the letters] in a mezuzah. The following letters should have crowns.5The Rambam lists the letters in the following halachah. Significantly, the letters he mentions here are not the same as he mentions in Chapter 2 with regard to tefillin. The Shulchan Aruch (Yoreh De'ah 288:7) rules that, in a mezuzah, just as in a Torah, one should place crowns on the letters, שעטנ"ז ג"ץ.

הלכה ג
פָּרָשָׁה רִאשׁוֹנָה יֵשׁ בָּהּ שֶׁבַע אוֹתִיּוֹת עַל כָּל אוֹת מֵהֶן שְׁלֹשָׁה זַיִנִּי״ן. וְאֵלּוּ הֵן. שִׁי״ן עַיִ״ן שֶׁל (דברים ו ד) ״שְׁמַע״ וְנוּ״ן דְּ(דברים ו ה) ״נַפְשְׁךָ״ וּתְרֵי זַיִנִּי״ן שֶׁל מְזוּזֹת וּתְרֵי טֵיתִי״ן שֶׁל (דברים ו ח) ״טֹטָפֹת״. וּפָרָשָׁה שְׁנִיָּה יֵשׁ בָּהּ שֵׁשׁ אוֹתִיּוֹת עַל כָּל אוֹת מֵהֶן שְׁלֹשָׁה זַיִנִּי״ן. וְאֵלּוּ הֵן. גִּימֶ״ל שֶׁל (דברים יא יד) ״דְגָנֶךָ״ וּתְרֵי זַיִנִּי״ן שֶׁל (דברים ו ט) ״מְזוּזוֹת״ וּתְרֵי טֵיתִי״ן שֶׁל טֹטָפוֹת וְצַדִּי״ק שֶׁל (דברים יא כא) ״הָאָרֶץ״. וְאִם לֹא עָשָׂה תָּגִין אוֹ שֶׁהוֹסִיף בָּהֶן אוֹ גָּרַע מֵהֶן לֹא פָּסַל. וְאִם כְּתָבָהּ שֶׁלֹּא בְּשִׂרְטוּט אוֹ שֶׁלֹּא דִּקְדֵּק בְּמָלֵא וְחָסֵר אוֹ שֶׁהוֹסִיף מִבִּפְנִים אֲפִלּוּ אוֹת אַחַת הֲרֵי זוֹ פְּסוּלָה:
כסף משנה
3.
In the first passage, there are seven letters which should each have three zeiynin upon it. They are: The shin and the ayin of [the word] Shema,1In Chapter 2, Halachah 6, the Rambam writes that, when writing tefillin, the ayin of the word Shema and the dalet of the word echad should be enlarged as in a Torah scroll. It is customary to write these letters in the same manner in mezuzot. the nun of [the word] nafsh'cha, the two zeiynin of [the word] mezuzot, and the two tettin of the word totafot.
In the second passage, there are six letters each of which should have three zeiynin upon it. They are: The gimmel of [the word] d'ganecha, the two zeiynin of [the word] mezuzot, the two tettin of the word totafot, and the tzadi of [the word] ha'aretz.
If no crowns were made, or one increased or decreased their number, [the mezuzah] is not invalidated.2As mentioned in the commentary on Chapter 2, Halachah 9, based on Rabbenu Asher's opinion, it is proper to add crowns if they have been omitted from the appropriate letters in a mezuzah. If the mezuzah was not written on ruled [parchment],3See Chapter 1, Halachah 12, where this subject is discussed. if [the scribe] was not exact with regard to the use of the full or short form [of the words,4See Chapter 2, Halachot 6-7. or if [the scribe] added even a single letter inside5Making additions on the outside of the mezuzah is discussed in the following halachah. [the mezuzah], it is invalidated.6Similarly, if a single letter is forgotten, the mezuzah is invalid (Shulchan Aruch, Yoreh De'ah 288:3).

הלכה ד
מִנְהָג פָּשׁוּט שֶׁכּוֹתְבִים עַל הַמְּזוּזָה מִבַּחוּץ כְּנֶגֶד הָרֶוַח שֶׁבֵּין פָּרָשָׁה לְפָרָשָׁה שַׁדַּי וְאֵין בָּזֶה הֶפְסֵד לְפִי שֶׁהוּא מִבַּחוּץ. אֲבָל אֵלּוּ שֶׁכּוֹתְבִין מִבִּפְנִים שְׁמוֹת הַמַּלְאָכִים אוֹ שֵׁמוֹת קְדוֹשִׁים אוֹ פָּסוּק אוֹ חוֹתָמוֹת הֲרֵי הֵן בִּכְלַל מִי שֶׁאֵין לָהֶם חֵלֶק לָעוֹלָם הַבָּא. שֶׁאֵלּוּ הַטִּפְּשִׁים לֹא דַּי לָהֶם שֶׁבִּטְּלוּ הַמִּצְוָה אֶלָּא שֶׁעָשׂוּ מִצְוָה גְּדוֹלָה שֶׁהִיא יִחוּד הַשֵּׁם שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא וְאַהֲבָתוֹ וַעֲבוֹדָתוֹ כְּאִלּוּ הוּא קָמֵעַ שֶׁל הֲנָיַת עַצְמָן כְּמוֹ שֶׁעָלָה עַל לִבָּם הַסָּכָל שֶׁזֶּהוּ דָּבָר הַמְהַנֶּה בְּהַבְלֵי הָעוֹלָם:
כסף משנה
4.
It is a common custom to write [God's name,] Shaddai,1This name serves as an acronym for the Hebrew words, שומר דלתות ישראל, "Guardian of the gates of Israel" (Mishnat Chassidim). on the outside of a mezuzah opposite the empty space left between the two passages.2The Kessef Mishneh cites the Zohar (Vol. III, 266a) which states that Shaddai should be written opposite the word, V'hayah. There is no difficulty in this, since [the addition is made] outside.3See also the Ramah (Yoreh De'ah 288:15) who states that it is also common to write the letters, כוזו במוכסז כוזו, opposite the words, י-ה-ו-ה א-להנו י-ה-ו-ה, on the outer side of a mezuzah. These letters are the letters which follow the letters in those names of God - i.e., the כ follows the י, the ז follows the ו.
Those, however, who write the names of angels, other sacred names, verses, or forms, on the inside [of a mezuzah] are among those who do not have a portion in the world to come.4In Hilchot Avodat Kochavim 11:12, the Rambam states:
A person who whispers an incantation over a wound and then recites a verse from the Torah, who recites a verse over a child so that he will not become scared, or who places a Torah scroll or tefillin over a baby so that it will sleep, is considered to be a soothsayer or one who casts spells. Furthermore, such people are included among those who deny the Torah, because they relate to the words of the Torah as if they are cures for the body, when, in fact, they are cures for the soul, as [Proverbs 3:22] states: "And they shall be life for your soul."
The inclusion of these people among "those who do not have a portion in the world to come" is based on Hilchot Teshuvah 3:8, which makes such a statement about "those who deny the Torah."
Not only do these fools nullify the mitzvah,5As stated in the previous halachah, any addition made on the inside of the mezuzah invalidates it. (Significantly, the Shulchan Aruch 288:15 states that it is forbidden to add to the inside of the mezuzah, but does not explicitly say that the mezuzah becomes invalidated.) but furthermore, they make from a great mitzvah [which reflects] the unity of the name of the Holy One, blessed be He, the love of Him, and the service of Him,6These are the subjects discussed in the two passages written within the mezuzah. a talisman for their own benefit. They, in their foolish conception, think that this will help them regarding the vanities of the world.7The Rambam's statements have aroused questions from many commentaries who note that, in several places, the Talmud associates a mezuzah with Divine protection - e.g., Menachot 33b, the Jerusalem Talmud, Pe'ah 1:1.
The Kessef Mishneh resolves this difficulty explaining that, although a mezuzah affords Divine protection, that protection comes, in and of itself, in reward for the fulfillment of the mitzvah. There is no need for any additions on man's part. Indeed, a person who makes additions to the mezuzah in an attempt to increase its influence demonstrates that he is concerned with "his own benefit" and "the vanities of the world" and not with the fulfillment of God's mitzvah. Therefore, he deserves the Rambam's severe words of criticism. See Likkutei Sichot, Vol. 19.1. Our translation follows the standard text of the Mishneh Torah. The Kessef Mishneh mentions another version which states "at the beginning or the end of the line." That version parallels the apparent source for the halachah, Menachot 31b.2. This custom is also recorded by Rav Yitzchak Alfasi, and earlier, in the halachot of Rav Yehudai Gaon. It is not clear when this custom was begun.3. As mentioned in Halachah 2, a space is left at the beginning of the line so that the passage, V'hayah im shamo'a, will be written in the s'tumah form.

הלכה ה
וּמִצְוָה לִכְתֹּב (דברים יא כא) ״עַל הָאָרֶץ״ בְּשִׁיטָה אַחֲרוֹנָה בֵּין בְּרֹאשׁ בֵּין (בְּאֶמְצַע) הַשִּׁיטָה. וְנָהֲגוּ כָּל הַסּוֹפְרִים לִכְתֹּב אוֹתָהּ בִּשְׁתַּיִם וְעֶשְׂרִים שִׁיטוֹת וְעַל הָאָרֶץ בְּרֹאשׁ שִׁיטָה אַחֲרוֹנָה. וְאֵלּוּ הֵן הָאוֹתִיּוֹת שֶׁבְּרֹאשׁ כָּל שִׁיטָה וְשִׁיטָה עַל הַסֵּדֶר. שְׁמַע. ה׳‎. הַדְּבָרִים. לְבָנֶיךָ. וּבְשָׁכְבְּךָ. בֵּין. וְהָיָה. מִצְוָה. בְּכָל. יוֹרֶה. עֵשֶׂב. פֶּן. וְהִשְׁתַּחֲוִיתֶם. הַשָּׁמַיִם. וַאֲבַדְתֶּם. וְשַׂמְתֶּם. אֹתָם. אֹתָם. בַּדֶּרֶךְ. וּבִשְׁעָרֶיךָ. אֲשֶׁר. עַל הָאָרֶץ:
כסף משנה
5.
It is a mitzvah to write al ha'aretz on the final line [of a mezuzah], either at the beginning or in the middle of the line. It has become universally accepted custom for scribes to write [mezuzot] with 22 lines, with al ha'aretz at the beginning of the final line.
These are the letters that appear at the beginning of each line in order: shema, י-ה-ו-ה, hadevarim, l'vanecha, uv'shochbicha, beyn, v'hayah, m'tzaveh, b'chol, yoreh, esev, pen, v'hishtachavitem, hashamayim, va'avad'tem, v'samtem, otam, otam, baderech, uvish'arecha, asher, al ha'aretz.

הלכה ו
כְּשֶׁכּוֹפְלִין אוֹתָהּ גּוֹלְלִין אוֹתָהּ מִסּוֹף הַשִּׁיטָה לִתְחִלָּתָהּ עַד שֶׁתִּמְצָא כְּשֶׁיִּפְתַּח הַקּוֹרֵא לִקְרוֹת יִקְרָא מֵרֹאשׁ הַשִּׁיטָה לְסוֹפָהּ. וְאַחַר שֶׁגּוֹלְלָהּ מַנִּיחָהּ בִּשְׁפוֹפֶרֶת שֶׁל קָנֶה אוֹ שֶׁל עֵץ אוֹ שֶׁל כָּל דָּבָר וּמְחַבֵּר אוֹתָהּ אֶל מְזוּזַת הַפֶּתַח בְּמַסְמֵר אוֹ חוֹפֵר בִּמְזוּזַת הַפֶּתַח וּמַכְנִיס בָּהּ הַמְּזוּזָה:
כסף משנה
6.
When [a mezuzah] is folded,1As the Rambam states, the intent is that the mezuzah be rolled. Folding a mezuzah is very undesirable, because it will cause the letters to crack. it should be rolled from the end of the line to its beginning2Menachot 31b states that a mezuzah should be rolled fromechad to Shema. The Rambam uses different terminology because, as stated in the previous halachah, the first line of the mezuzah does not end with echad. so that when a reader rolls it open, he will be able to read from the beginning of the line to the end.3i.e., when one unrolls the mezuzah, the initial word of the line appears first.
After rolling it, one should place it in a tube made of reed, wood, or any other substance and affix it to the doorpost of one's entrance with a nail.4The Shulchan Aruch (Yoreh De'ah 289:4) states that one should affix it "with nails." The intent is that the mezuzah should be firmly affixed so that it is not dangling from one side. Alternatively, one should hollow out the doorpost and place the mezuzah within.5As mentioned in Halachah 8, one should not place it deeper than a handbreadth within the doorpost.

הלכה ז
וְקֹדֶם שֶׁיִּקְבָּעֶנָּה בִּמְזוּזַת הַפֶּתַח מְבָרֵךְ תְּחִלָּה. בָּרוּךְ אַתָּה יְיָ׳‎ אֱלֹהֵינוּ מֶלֶךְ הָעוֹלָם אֲשֶׁר קִדְּשָׁנוּ בְּמִצְוֹתָיו וְצִוָּנוּ לִקְבֹּעַ מְזוּזָה. וְאֵינוֹ מְבָרֵךְ בִּשְׁעַת כְּתִיבָתָהּ שֶׁקְּבִיעָתָהּ זוֹ הִיא הַמִּצְוָה:
כסף משנה
7.
Before affixing it on the doorpost of the entrance, one should recite the blessing:1as is done before the fulfillment of a positive commandment. This blessing should also be recited again when affixing a mezuzah which falls from the doorpost. There is a question whether a mezuzah should be recited when affixing it after removing it to have it checked (Pitchei Teshuvah 289:1). "Blessed are You, God, our Lord, King of the universe, who has sanctified us with His commandments and commanded us to affix a mezuzah."
One2Significantly, in Hilchot Berachot 11:12-13, the Rambam states that when one affixes a mezuzah for a colleague, the blessing should conclude, "concerning the affixing of a mezuzah."
Although the verses which relate the command to affix a mezuzah state, "And you shall write...."
should not recite a blessing when writing [the mezuzah], because affixing it fulfills the mitzvah.313 In the listing of the mitzvot at the beginning of these halachot and in Sefer HaMitzvot (positive commandment 15), the Rambam also states that the mitzvah is to "affix a mezuzah."
With regard to the blessings, see Hilchot Berachot 11:8, which states:
For every mitzvah whose performance fulfills one's obligation, one recites the blessing when one performs it. Whenever a mitzvah has a further commandment involved after its performance, one should not recite a blessing until one performs the latter commandment. For example, when one makes a sukkah, a lulav,... tefillin, or a mezuzah, one does not recite a blessing when one makes them.... When does one recite the blessing? When one dwells in the sukkah, shakes the lulav,... wears the tefillin, or affixes the mezuzah.
Note also the comments of the Siftei Cohen 289:1, who writes that the blessing, Shehecheyanu, is not recited before affixing a mezuzah.

הלכה ח
תְּלָאָהּ בְּמַקֵּל פְּסוּלָה שֶׁאֵין זוֹ קְבוּעָה. הִנִּיחָהּ אַחֲרֵי הַדֶּלֶת לֹא עָשָׂה כְּלוּם. חָפַר בִּמְזוּזַת הַפֶּתַח וְהִכְנִיס הַמְּזוּזָה כְּמוֹ נֶגֶר וְהִיא כִּבְרִיחַ הַקְּרָשִׁים בַּטַּבָּעוֹת פְּסוּלָה. הֶעֱמִיק לָהּ טֶפַח פְּסוּלָה. חָתַךְ קָנֶה וְהִכְנִיס בּוֹ מְזוּזָה וְאַחַר כָּךְ חִבֵּר הַקָּנֶה אֶל קָנִים אֲחֵרִים וְהֶעֱמִיד מִן הַכּל מְזוּזַת הַפֶּתַח פְּסוּלָה מִפְּנֵי שֶׁקָּדְמָה קְבִיעַת הַמְּזוּזָה לַעֲשִׂיַּת מְזוּזַת הַפֶּתַח:
כסף משנה
8.
If one suspends [a mezuzah] within a pole,1i.e., rather than placing the mezuzah in a tube affixed to the doorpost, one places the mezuzah within a pole which stands next to - but is not permanently affixed to - the doorpost it is unacceptable, because it has not been affixed.2Deuteronomy 6:9 states that a mezuzah must be placed "on your gates." Unless the mezuzah is affixed to the gateway, it does not meet this criteria (Menachot 32b). If one positions it behind the door, it is as if one has done nothing.3Deuteronomy, ibid., states that a mezuzah must be placed "on the doorposts of your houses" and not "within the doorposts" (Kitzur Shulchan Aruch 11:9).
The Kitzur Shulchan Aruch, ibid., states that if one fears that the mezuzah will be stolen or defaced, it may be placed within the door. It should, however, be placed on the back of the doorpost, but not on the wall next to the doorpost. (See also Chapter 6, Halachah 12.)

Should one hollow out the doorpost and place a mezuzah within it horizontally, as the rods were put through the rings [in the Sanctuary],4See Exodus 26:26-29. it is unacceptable.5Rather, the mezuzah should stand directly upright. This opinion is quoted by the Shulchan Aruch (Yoreh De'ah 289:6). The Ramah, however, notes the opinion of Rabbenu Tam, who favors the horizontal position, explaining that if it is placed vertically, it is unacceptable.
Accordingly, the Ramah suggests affixing the mezuzah at a slant, thereby adhering to both views. This is the common custom at present.
Should one place it deeper than a handbreadth [within the doorpost], it is unacceptable.6This also is not "on the doorposts of your houses."
Should one cut a reed in half and insert a mezuzah within, and afterwards connect this reed with other reeds, making a doorpost for the house from them,7Although if the reed with the mezuzah had been affixed to an existing doorpost, it would have been acceptable. In this instance, it is unacceptable, because the affixing of the mezuzah preceded the making of the doorpost of the entrance.8As the Rambam explains in Hilchot Tzitzit 1:16, Deuteronomy 22:12 states that one should "make fringes" on one's garments. Menachot 40b states that this teaches us that we must make the tzitzit and not use those which are already made.
Menachot 33b states that the same principle applies here. Since the mezuzah was placed inside the pole before it became part of the doorpost, it is not acceptable.

הלכה ט
מְזוּזַת הַיָּחִיד נִבְדֶּקֶת פַּעֲמַיִם בְּשָׁבוּעַ. וּמְזוּזַת רַבִּים פַּעֲמַיִם בְּיוֹבֵל. שֶׁמָּא נִקְרְעָה מִמֶּנָּה אוֹת אַחַת אוֹ נִמְחֲקָה מִפְּנֵי שֶׁהִיא קְבוּעָה בַּכְּתָלִים מַרְקֶבֶת:
כסף משנה
9.
A mezuzah [placed] on private [property] should be checked1at least twice in seven years, and a mezuzah [placed] on public [property]2e.g., at the entrance to a courtyard or to a city. (See Chapter 6, Halachah 8.) should be checked twice in fifty years,3Rashi, Yoma 11a, explains that if more stringent requirements were instituted, it is likely that they would be ignored. Every individual would rationalize that it is somebody else's responsibility. lest a letter have become torn or faded.4A small crack can render the mezuzah unacceptable. Since it is affixed within a wall,5as opposed to tefillin, whose checking is governed by different requirements. (See Chapter 2, Halachah 11.) there is the possibility that it will decay.6At present, it is customary to check mezuzot more frequently. The ink and parchment we use are different, and there is a greater tendency for letters to fade or crack. Also, there are many scribes whose calligraphy is not professional, and errors which render the mezuzah unacceptable are frequently discovered.
[For the above reasons, it is also customary to wrap mezuzot in plastic to prevent the possibility of decay.]

הלכה י
הַכּל חַיָּבִין בִּמְזוּזָה אֲפִלּוּ נָשִׁים וַעֲבָדִים. וּמְחַנְּכִים אֶת הַקְּטַנִּים לַעֲשׂוֹת מְזוּזָה לְבָתֵּיהֶם. הַשּׂוֹכֵר בַּיִת בְּחוּצָה לָאָרֶץ וְהַדָּר בְּפֻנְדָּק בְּאֶרֶץ יִשְׂרָאֵל פָּטוּר מִן הַמְּזוּזָה שְׁלֹשִׁים יוֹם. אֲבָל הַשּׂוֹכֵר בַּיִת בְּאֶרֶץ יִשְׂרָאֵל חַיָּב בִּמְזוּזָה מִיָּד:
כסף משנה
10.
Everyone is obligated [to fulfill the mitzvah of] mezuzah, even women and slaves.1Since mezuzah is a positive commandment whose fulfillment is not limited to a specific time, its fulfillment is incumbent on all Jews. Minors2who are exempt from the obligation to perform any mitzvot mid'oraita ("according to Torah law"), should be educated to affix a mezuzah to [the doors of] their homes.3as part of the Rabbinic command to educate them to perform mitzvot.
A person who rents a dwelling in the diaspora, and a person who rents4It would appear that if one purchases a dwelling - even in the diaspora - one is obligated to affix a mezuzah immediately. a room in a hotel in Eretz Yisrael, are exempt from the obligation [to affix a] mezuzah for thirty days.5As explained in Chapter 6, Halachah 1, a person is obligated to place a mezuzah only on a permanent dwelling. Hence, until this time period has passed, these dwellings are not considered to be permanent. One who rents a house in Eretz Yisrael, however, is obligated [to affix a] mezuzah immediately.6Because of the importance of dwelling in Eretz Yisrael, even a temporary dwelling is of significance (Menachot 44a, Tur, Yoreh De'ah 286).

הלכה יא
הַמַּשְׂכִּיר בַּיִת לַחֲבֵרוֹ עַל הַשּׂוֹכֵר לְהָבִיא מְזוּזָה וְלִקְבֹּעַ אוֹתָהּ אֲפִלּוּ הָיָה נוֹתֵן שָׂכָר עַל קְבִיעָתָהּ. מִפְּנֵי שֶׁהַמְּזוּזָה חוֹבַת הַדָּר הִיא וְאֵינָהּ חוֹבַת הַבַּיִת. וּכְשֶׁהוּא יוֹצֵא לֹא יִטְּלֶנָּה בְּיָדוֹ וְיֵצֵא. וְאִם הָיָה הַבַּיִת שֶׁל כּוּתִי הֲרֵי זֶה נוֹטְלָהּ כְּשֶׁיֵּצֵא:
כסף משנה
11.
When a person rents a dwelling to a colleague, the tenant is obligated to obtain a mezuzah and affix it.1Even though the Torah states that a mezuzah must be placed on the entrance to "your house," Bava Metzia 101b states that this refers to the person living within, and not the owner. [This applies] even if he2the tenant would pay to have it affixed.3Even if the tenant offers to pay the owner to find a mezuzah and affix it, the owner is not required to accept the offer. The Ramah (Yoreh De'ah 291:2) adds that even if a person rents a house on the condition that it has mezuzot, and he discovers that they are lacking, he may not withdraw from the rental agreement on the grounds that the agreement was based on a misconception. [The rationale is] that a mezuzah is an obligation incumbent on the person dwelling [in the house], and is not incumbent on the house.4Compare to Hilchot Tzitzit 3:10, which states that tzitzit "are not an obligation on the garment, but on the person who possesses the garment."
These statements, however, must be understood in the context of Hilchot Berachot 11:2, which states:
There are positive commandments which a person is required to pursue and make every effort to fulfill - e.g., tefillin, sukkah, lulav, and shofar. These are called obligations, since a person is obliged to fulfill them.... There are other mitzvot which are not obligations, but rather are left to the person's volition - for example, a mezuzah and a guardrail. A person is not obligated to live in a house which requires a mezuzah so that he could fulfill the mitzvah of mezuzah. Should he desire, he may dwell in a tent or a ship for his entire life.
To summarize, according to the Rambam the mitzvah of mezuzah is incumbent on the person (gavra) and not on the house (cheftza). Nevertheless, it is incumbent upon him only when he lives in a house that requires a mezuzah.

When [the tenant] leaves [the dwelling, however], he should not take it with him5for leaving the house without a mezuzah leaves it open to undesirable influences (Tosafot, Bava Metzia, ibid.). Alternatively, removing a mezuzah may bring harm to the person who removes it (Sefer Chasidim). unless the dwelling belongs to a gentile.6or will be rented to a gentile. Note the Hagahot Maimoniot, which state that a dwelling which a Jew rents from a gentile does not require a mezuzah. This opinion is not, however, accepted by the Shulchan Aruch (Yoreh De'ah 286:23) In that instance, he should remove it when he leaves.7lest the gentile desecrate it. Note the comments of the Ramah (Yoreh De'ah 291:2), who states that it is forbidden to give a mezuzah to a gentile to affix on his door. Nevertheless, if the Jew is frightened that refusing the gentile will generate severe negative feelings, he may leave him the mezuzah.

אהבה הלכות תפילין ומזוזה וספר תורה פרק ה
Ahavah Tefillin, Mezuzah, and Sefer Torah Chapter 5